Array to String

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Piero

    Array to String

    Hi, i have a string array, how can i convert it to a string?
  • Marc Gravell

    #2
    Re: Array to String

    For example:

    string[] foo = {"abc","def","g hi"};
    string s1 = string.Concat(f oo);
    string s2 = string.Join(" ", foo);

    Marc

    Comment

    • Piero

      #3
      Re: Array to String

      On Apr 2, 10:44 am, Marc Gravell <marc.grav...@g mail.comwrote:
      For example:
      >
      string[] foo = {"abc","def","g hi"};
      string s1 = string.Concat(f oo);
      string s2 = string.Join(" ", foo);
      >
      Marc
      My result is a one string with the "\" separetor....
      i use String.Join but the result is :
      string s1= "abc\"def\"ghi\ "; but it's wrong!
      the right result must have s1 = "abc\def\gh i\";

      Comment

      • Marc Gravell

        #4
        Re: Array to String

        string s1= "abc\"def\"ghi\ "; but it's wrong!

        Where are you looking at this? The IDE tool-tip displays it with
        escape symbols. Try Console.WriteLi ne(s1) - it might actually be
        right.

        Marc

        Comment

        • Piero

          #5
          Re: Array to String

          On Apr 2, 11:22 am, Marc Gravell <marc.grav...@g mail.comwrote:
          string s1= "abc\"def\"ghi\ "; but it's wrong!
          >
          Where are you looking at this? The IDE tool-tip displays it with
          escape symbols. Try Console.WriteLi ne(s1) - it might actually be
          right.
          >
          Marc
          i look this when i create a txt file. if i try with console.writeli ne
          it's right!
          but i must create an output file...

          Comment

          • Piero

            #6
            Re: Array to String

            thank's to all! i resolve my problem!
            my wrong istruvtion is String s1= string.join("\" ",foo) and this
            concatenates a backshals and quotes but i must concatenates only a
            backslash and the right istruction is String s1 = string.join("\
            \",foo).

            thaks
            bye

            Comment

            • Marc Gravell

              #7
              Re: Array to String

              my wrong istruvtion is String s1= string.join("\" ",foo) and this
              concatenates a backshals and quotes
              Actually that just concatenates quotes... but glad you are sorted ;-p

              If you are doing a lot of this, the alternative syntax might be
              clearer:

              "\\" is the same as @"\";

              Comment

              Working...