Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Need help in explicit convertion of char[] to string

Need help in explicit convertion of char[] to string

Scheduled Pinned Locked Moved C#
helpdata-structuresquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Ashraj1982
    wrote on last edited by
    #1

    Hi, Can any one tell me explicit convertion of char array to string? i have string str and char strdata[25]; now i want to assign strdata value to the string called str. I'm getting error " cannot implicitly convert type 'char[]' to 'string' " Any idea?

    N L 2 Replies Last reply
    0
    • A Ashraj1982

      Hi, Can any one tell me explicit convertion of char array to string? i have string str and char strdata[25]; now i want to assign strdata value to the string called str. I'm getting error " cannot implicitly convert type 'char[]' to 'string' " Any idea?

      N Offline
      N Offline
      NaNg15241
      wrote on last edited by
      #2

      there is no explicit\implicit way on converting char[] to string, and overriding will cause a-lot of problems. just use this function (you can change and it's better to change the static in it):

      static private string CtoS(char[] charArr)
      {
      string tmp = "";
      for (int i = 0; i < charArr.Length; i++)
      tmp = tmp + charArr[i];
      return tmp;
      }

      NaNg

      A 1 Reply Last reply
      0
      • N NaNg15241

        there is no explicit\implicit way on converting char[] to string, and overriding will cause a-lot of problems. just use this function (you can change and it's better to change the static in it):

        static private string CtoS(char[] charArr)
        {
        string tmp = "";
        for (int i = 0; i < charArr.Length; i++)
        tmp = tmp + charArr[i];
        return tmp;
        }

        NaNg

        A Offline
        A Offline
        Ashraj1982
        wrote on last edited by
        #3

        Thanks.... But i dot want to concatenate bcoz the string has to be over written for every line read from the file.

        1 Reply Last reply
        0
        • A Ashraj1982

          Hi, Can any one tell me explicit convertion of char array to string? i have string str and char strdata[25]; now i want to assign strdata value to the string called str. I'm getting error " cannot implicitly convert type 'char[]' to 'string' " Any idea?

          L Offline
          L Offline
          lmoelleb
          wrote on last edited by
          #4

          string str = new string(strdata);

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups