-1

This question already has an answer here:

I read on a few other posts with solutions similar to my question but none of them seemed to work when I compiled them on solidity.

I am trying to simply add two strings and return the value.

contract AddTwoStrings {

string sentence;
string more_text;

function AddTwoStrings(){
    sentence = "this is a sentence";
    more_text = " additional text added.";
}


function add_string() returns (string str){
    str = sentence + more_text; //
    return str;
}

}

marked as duplicate by Ismael, lungj, Thomas Jay Rush, carver, Richard Horrocks Aug 28 '17 at 20:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

Contact two strings as follows:

contract Test {

  function concat(string str1, string str2) returns (string){

        bytes memory bs1 = bytes(str1);
        bytes memory bs2 = bytes(str2);

        uint len1 = bs1.length;
        uint len2 = bs2.length;

        string memory temp = new string(len1 + len2);
        bytes memory result = bytes(temp);

        uint index = 0;
        for (uint i = 0; i < len1; i++) {
            result[index++] = bs1[i];

        }
        for (i = 0; i < len2; i++) {
            result[index++] = bs2[i];

        }
        return string(result);
    }

}

Hope it helps~

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