Loading...
In this chapter, we will see how to create a function. In this function we can do a concatenation method means we will add the string variables.
String is the major role data type in any programming language. They can define the value in single quotes as well as double quotes.
Example:-
string firstName = "Anurag";
string lastName = "Saini";
if you want to return the concatenation word then you will write in return method-
string(abi.encodePacked(firstName, lastName));
If you want to compare two strings then, you have only change the concatenation method to compare the method
Example:-
(abi.encodePacked(firstName)==abi.encodePacked(lastName));
Finally, you can do or construct the program of the concatenation of two strings. If you store the value already-
pragma solidity ^0.4.24;
contract Arrays {
string firstName = "Anurag";
string lastName = "Saini";
function concat()public view returns(string memory){
return string(abi.encodePacked(firstName, lastName));
}
}
If you want to concatenation the dynamic value then,
pragma solidity ^0.4.24;
contract Arrays {
function concat(string memory a, string memory b)public view returns(string memory){
return string(abi.encodePacked(a,b));
}
}