CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009
    Posts
    23

    Convert a String to an array of single characters?

    Hi everyone!

    (I am using MS' Visual C# 2008 Express, in case that makes any difference...)

    What I want to do is this: Take the content of a string (e.g. "Hello") and 'convert' it to an array that stores each character seperately (e.g. { "H", "e", "l", "l", "o" }). Can somebody tell me how to do that?

    Additionally, is there a function that returns the index of an entity within an array? That is, if I was searching for an "e" in { "H", "e", "l", "l", "o" }, it'd return 1.

    Sorry if these questions are dumb but I find it hard to come up with good key words for a google search. :/

    Thanks in advance! (:
    Last edited by TryingToC#; December 13th, 2009 at 02:30 AM.

  2. #2
    Join Date
    Sep 2006
    Posts
    31

    Re: Convert a String to an array of single characters?

    Actually a string is an array of chars so you can just do this
    String s ="Hello";
    then s[0] will be 'H' and s[1] will be 'e' and so on...

    for the index you can use this:
    String s="Hello";
    textBox1.Text = "" + s.IndexOf('l');
    wich will return 2

    greets kristof

  3. #3
    Join Date
    Dec 2009
    Posts
    23

    Re: Convert a String to an array of single characters?

    Ha, that's easier than expected.

    Thank you, kristof!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured