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

function getArray() public view returns (string) 
    //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. Dec 20, 2018 at 12:50
  • 3
    Why? What is your use case that would make this an appropriate thing to do on chain? Dec 20, 2018 at 12:53
  • Usually, everything related to displaying information on the screen should be done client-side, not in the smart contract.
    – Jesbus
    Dec 20, 2018 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. Dec 20, 2018 at 15:05

1 Answer 1


Got it!!

string company_name;
function getComp(string memory arr) public returns (string memory) 

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;
  • You are not really concatenating an adhoc array of strings, but three well known variables.
    – Qwerty
    Jan 5 at 15:00

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.