-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path30Day-Strings.sol
33 lines (29 loc) · 1.08 KB
/
30Day-Strings.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.9.0;
contract Day6 {
function length(string memory str) public pure returns (uint256) {
bytes memory str_bytes = bytes(str);
return str_bytes.length;
}
//concatenate ( ) - This function will take two arguments i.e string 1 and string 2. It will concatenate string 1 and string 2 and will return the concatenated string.
function concatenate(string memory str1, string memory str2)
public
pure
returns (string memory)
{
bytes memory str_bytes1 = bytes(str1);
bytes memory str_bytes2 = bytes(str2);
string memory str = new string(str_bytes1.length + str_bytes2.length);
bytes memory str_bytes = bytes(str);
uint256 k = 0;
for (uint256 i = 0; i < str_bytes1.length; i++) {
str_bytes[k] = str_bytes1[i];
k++;
}
for (uint256 i = 0; i < str_bytes2.length; i++) {
str_bytes[k] = str_bytes2[i];
k++;
}
return string(str_bytes);
}
}