Skip to content

Character concatenation/formatting #133

Closed Answered by pfusik
Entrivax asked this question in Q&A
Discussion options

You must be logged in to vote

That's correct, except it should be:

    public static string() GetMessage(string str)
    {
        string() out = "First character: ";
        // Here goes some parsing steps...
        out = $"{out}{str.Substring(0, 1)}";
        // Other steps...
        out = $"{out}\nSecond character: {str.Substring(1, 1)}";
        return out;
    }

Note the use of string() for string storage. This is crucial if you target C or C++. I'll try to add errors that prevent the incorrect usage of string references.

Alternatively:

        out += str.Substring(0, 1);

etc.

Also, the above is only fine if you work on ASCII characters. For Unicode, the concept of "character" is more complex and please make su…

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@Entrivax
Comment options

Comment options

You must be logged in to vote
1 reply
@Entrivax
Comment options

Comment options

You must be logged in to vote
1 reply
@Entrivax
Comment options

Answer selected by Entrivax
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants