-1

I am trying to concatenate a whole array of string into a single array for printing purpose.

function getArray() public view returns (string) 
{
    arr.push("Max");
    arr.push("good");
    arr.push("well");
    .
    . 
    .
    //arr[]-Array of strings
    //b-string type variable
    return b;
}

output should be like -Maxgoodwell

  • 2
    For clarity of your question, you should have the arr.push part in a different function. – goodvibration Dec 20 '18 at 12:50
  • 3
    Why? What is your use case that would make this an appropriate thing to do on chain? – Thomas Clowes Dec 20 '18 at 12:53
  • Usually, everything related to displaying information on the screen should be done client-side, not in the smart contract. – Jesse Busman Dec 20 '18 at 13:57
  • 1
    @JesseBusman: True. Unless this functionality should somehow be used on-chain (i.e., by another contract), there's no point implementing it. This question is lacking the context required for determining whether or not this function is to be called from another conttract, but I doubt that this is indeed the case here. – goodvibration Dec 20 '18 at 15:05
0

Got it!!

string company_name;
function getComp(string memory arr) public returns (string memory) 
{
    company_name=concate(arr);
}

function concate(string memory arr) internal view returns(string memory)
{
    return string(abi.encodePacked(company_name," ",arr));
}

function ShowComp() public view returns (string memory)
{
    return company_name;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.