-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb77267
commit 34c2865
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} |