none
How to Append new line in each element of string array RRS feed

  • Question

  • Hello Everyone, 

    I am facing bit problem with string array. pls help me here

    Actually i have a string like below

    string[] str1;
    str1 = new string[5]{ “Element 1”, “Element 2”, “Element 3”, “Element 4”, “Element 5” };

    Here i want to check each element in string array has new line or not. If it's not having new line append to it, i need to append new line like below

    str1 = new string[5]{ “Element 1\n”, “Element 2\n”, “Element 3\n”, “Element 4\n”, “Element 5\n” };

    How to achieve this. 

    Pls help me

    Thanks,

    Thursday, February 27, 2020 7:21 AM

Answers

  • One of possibilities:

       for( int i = 0; i < str1.Length; ++i )

       {

          if( !str1[i].EndsWith( "\n" ) ) str1[i] += "\n";

       }

    • Marked as answer by Learning Rocks Thursday, February 27, 2020 12:26 PM
    Thursday, February 27, 2020 8:13 AM