区块链学堂(22):String 数组类型
2018-01-05 09:18
267 查看
String类型的官方定义
String literals are written with either double or single-quotes (“foo” or ‘bar’). They do not imply trailing zeroes as in C; “foo”` represents three bytes not four. As with integer literals, their type can vary, but they are implicitly convertible to bytes1,
…, bytes32, if they fit, to bytes and to string.
String literals support escape characters, such as \n, \xNN and \uNNNN. \xNN takes a hex value and inserts the appropriate byte, while \uNNNN takes a Unicode codepoint and inserts an UTF-8 sequence. 引用自here
Step 1: 首先撰写一个String数组的contract和构造函数
Step 2: 添加一个Add function
Step 3: 添加一个Update function
大家注意一下,如果index>strArr.length-1, 此时应抛出异常
Step 4: 添加一个ValueOf function
Step 5: 添加一个DeleteAt function
原文:http://www.ethchinese.com/?p=1022
QQ群:559649971 (区块链学堂粉丝群)
个人微信:steven_k_colin
获取最新区块链咨询,请关注《以太中文网》微信公众号:以太中文网
String literals are written with either double or single-quotes (“foo” or ‘bar’). They do not imply trailing zeroes as in C; “foo”` represents three bytes not four. As with integer literals, their type can vary, but they are implicitly convertible to bytes1,
…, bytes32, if they fit, to bytes and to string.
String literals support escape characters, such as \n, \xNN and \uNNNN. \xNN takes a hex value and inserts the appropriate byte, while \uNNNN takes a Unicode codepoint and inserts an UTF-8 sequence. 引用自here
String数组类型定义
string[] strArr
String数组的增删改查
Step 1: 首先撰写一个String数组的contract和构造函数pragma solidity 0.4.10; contract Demo { string[] public strArr; function Demo() { strArr.push("init"); } }
Step 2: 添加一个Add function
function Add(string str) { strArr.push(str); }
Step 3: 添加一个Update function
function Update(uint index, string str) { if (index > strArr.length-1) throw; strArr[index] = str; }
大家注意一下,如果index>strArr.length-1, 此时应抛出异常
Step 4: 添加一个ValueOf function
function ValueOf(uint index) returns (string str){ if (index > strArr.length-1) throw; return strArr[index]; }
Step 5: 添加一个DeleteAt function
function DeleteAt(uint index) { uint len = strArr.length; if (index > len-1) throw; for (uint i = index; i<len-1; i++) { strArr[i] = strArr[i+1]; } delete strArr[len-1]; strArr.length--; }
原文:http://www.ethchinese.com/?p=1022
QQ群:559649971 (区块链学堂粉丝群)
个人微信:steven_k_colin
获取最新区块链咨询,请关注《以太中文网》微信公众号:以太中文网
相关文章推荐
- 区块链学堂(21):数组类型
- string数组类型转换为int数组(数组类型之间的转换)
- StringToDoubleArray函数:IDL中将字符串转换为double类型的数组
- Java中char数组与字符串String类型的转换
- String 类型切割成数组-转int数组-升列排序-拼接字符串、需求 有如下一个字符串 "91 27 46 38 50"
- 字符串String类型 、数组 Array类型
- String数组的输入转换成int类型后再进行排列
- C#中将Object数组转换为String(或者其他类型)的数组(集合)
- C++ TCHAR数组转换为C#的System::String类型
- java中utf-8编码的byte数组转换成String类型代码
- String字符串与字符(char类型)数组互相转换
- 区块链学堂(12):Browser-solidity 3–数组增删改查的合约
- Java 集合转数组(String类型)
- 《区块链学堂》第四课:以太坊高级数据类型和代币合约(附课程视频)
- 仍然是数组和指针的初始化,以及string类型的赋初始值
- Array/数组类型的转换方法——toLocaleString()
- 如何实现将String类型数组转换成int类型 并进行排序
- JAVA的数组 && 原始类型和引用类型以及String与int long相互转化 && String与byte[]相互转化
- C#新手入门代码 将一维string数组转换成二维char类型输出并输出
- char*数组(c类型字符串)和c++中的string的转换、字符串比较、char*数组等问题