My Image
CoursesQuizzesProblemsContestsSmartBooks
Contest!

No results found

LOGINREGISTER
My ProgressCoursesQuizzesProblemsContestsSmartbooks
Published on 4 Jul 2021
Create a function to concat two strings
Let's play with string
img
Anurag Saini
0
Like
185

String

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";

Concatenation method

if you want to return the concatenation word then you will write in return method-

string(abi.encodePacked(firstName, lastName));

Compare Method

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));

Fixed value:-

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));
   }
  
}

 

Dynamic Value:-

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));
   }
  
}
Enjoyed the SmartBook?
Like
logo
contact@dapp-world.com
Katraj, Pune, Maharashtra, India - 411048

Follow Us

linkedintwitteryoutubediscordinstagram

Products

  • SmartBooks
  • Courses
  • Quizzes
  • Assessments

Support

  • Contact Us
  • FAQ
  • Privacy Policy
  • T&C

Backed By

ah! ventures

Copyright 2023 - All Rights Reserved.

Recommended from DAppWorld
img
1 May 2021
How to connect Ganache with Metamask and deploy Smart contracts on remix without
Set up your development environment with (Metamask + Ganache + Remix) and skip truffle :)
3 min read
11508
5
img
8 Jul 2021
How to interact with smart contarct from backend node js
call and send functions from backend server side using nodejs
3 min read
8103
2
img
18 Aug 2021
Send transaction with web3 using python
Introduction to web3.py and sending transaction on testnet
3 min read
6229
5
img
5 Aug 2021
Deploy Smart Contract on Polygon POS using Hardhat
how to deploy smart contracts on polygon pos chain using hardhat both mainnet and testnet ?
3 min read
5540
3