Skip to content

Instantly share code, notes, and snippets.

@code-brewer
Created September 28, 2018 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save code-brewer/8cec6aa2afea7700e9a450fb96b7ef38 to your computer and use it in GitHub Desktop.
Save code-brewer/8cec6aa2afea7700e9a450fb96b7ef38 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.25+commit.59dbf8f1.js&optimize=false&gist=
pragma solidity 0.4.25;
/*数组类型Demo*/
contract DemoTypes303 {
/*String数组例子*/
string[] strArr;
function add(string str) public {
strArr.push(str);
}
function getStrAt(uint n) public constant returns (string s){
string storage tmp = strArr[n];
return tmp;
}
function updateStrAt(uint n, string str) public {
strArr[n] = str;
}
function deleteStrAt(uint index) public {
uint len = strArr.length;
if (index >= len) return;
for (uint i = index; i<len-1; i++) {
strArr[i] = strArr[i+1];
}
delete strArr[len-1];
strArr.length--;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment