Created
September 28, 2018 03:08
-
-
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=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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