Convert String to Char[]

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

    #1

    Convert String to Char[]

    Hi guys, i've seen it in VC++

    but in C# how do i conver string to char[20]??

    in c++ is like http://support.microsoft.com/?kbid=311259

    Regards


  • Vadym Stetsyak

    #2
    Re: Convert String to Char[]

    Hello, Rick!

    R> but in C# how do i conver string to char[20]??

    R> in c++ is like http://support.microsoft.com/?kbid=311259

    Does string.ToCharAr ray() suit your needs?

    --
    Regards, Vadym Stetsyak
    www: http://vadmyst.blogspot.com

    Comment

    • pvdg42

      #3
      Re: Convert String to Char[]


      "Rick" <elmargaro@hotm ail.com> wrote in message
      news:OqXHjyHPGH A.140@TK2MSFTNG P12.phx.gbl...[color=blue]
      > Hi guys, i've seen it in VC++
      >
      > but in C# how do i conver string to char[20]??
      >
      > in c++ is like http://support.microsoft.com/?kbid=311259
      >
      > Regards
      >[/color]
      I'm sure there are more elegant ways, but you can simply subscript your
      String object to convert character by character:

      char[] myString = new char[20];

      String myStuff = "My stuff";

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

      {

      myString[i] = myStuff[i];

      }

      Console.WriteLi ne(myString);


      --
      Peter [MVP Visual Developer]
      Jack of all trades, master of none.


      Comment

      • Kris

        #4
        Re: Convert String to Char[]

        Hi Rick,

        Use string.ToCharAr ray() method to convert.

        Thanks,
        Kris

        Comment

        • Rick

          #5
          Re: Convert String to Char[]

          it works!! Thanks a lot!!!


          "Vadym Stetsyak" <vadym_s@ukr.ne t> escribio en el mensaje
          news:ubxbo1HPGH A.2236@TK2MSFTN GP15.phx.gbl...[color=blue]
          > Hello, Rick!
          >
          > R> but in C# how do i conver string to char[20]??
          >
          > R> in c++ is like http://support.microsoft.com/?kbid=311259
          >
          > Does string.ToCharAr ray() suit your needs?
          >
          > --
          > Regards, Vadym Stetsyak
          > www: http://vadmyst.blogspot.com[/color]


          Comment

          • Rick

            #6
            Re: Convert String to Char[]

            Thanks a lot!!!

            Rick

            "Kris" <krishna.bitla@ gmail.com> escribió en el mensaje
            news:1141141717 .147149.213220@ i40g2000cwc.goo glegroups.com.. .[color=blue]
            > Hi Rick,
            >
            > Use string.ToCharAr ray() method to convert.
            >
            > Thanks,
            > Kris
            >[/color]


            Comment

            • Rick

              #7
              Re: Convert String to Char[]

              jejeje

              that was the first option i thought
              but it works with
              ..ToCharArray()



              Thanks!!!

              "pvdg42" <pvdg42@newsgro ups.nospam> escribió en el mensaje
              news:%23656u4HP GHA.3732@TK2MSF TNGP10.phx.gbl. ..[color=blue]
              >
              > "Rick" <elmargaro@hotm ail.com> wrote in message
              > news:OqXHjyHPGH A.140@TK2MSFTNG P12.phx.gbl...[color=green]
              >> Hi guys, i've seen it in VC++
              >>
              >> but in C# how do i conver string to char[20]??
              >>
              >> in c++ is like http://support.microsoft.com/?kbid=311259
              >>
              >> Regards
              >>[/color]
              > I'm sure there are more elegant ways, but you can simply subscript your
              > String object to convert character by character:
              >
              > char[] myString = new char[20];
              >
              > String myStuff = "My stuff";
              >
              > for (int i = 0; i < myStuff.Length; i++)
              >
              > {
              >
              > myString[i] = myStuff[i];
              >
              > }
              >
              > Console.WriteLi ne(myString);
              >
              >
              > --
              > Peter [MVP Visual Developer]
              > Jack of all trades, master of none.
              >
              >[/color]


              Comment

              Working...