Results 1 to 5 of 5

Thread: ChartAt(index) in C#?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252

    ChartAt(index) in C#?

    Hi,

    The charAt method returns a character value equal to the character at the specified index. The first character in a string is at index 0, the second is at index 1, and so forth. Values of index out of valid range return an empty string.

    CharAt is not available in C# or something like that. I would like to know which member I could use, so I can do the same thing as CharAt?

    Thanks,
    McoreD

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196

    Re: ChartAt(index) in C#?

    Try this:
    Code:
    string str = "hello world";
    Console.WriteLine( str[0] ); //returns "h";
    Console.WriteLine( str[2] ); //returns "l";

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252

    Re: ChartAt(index) in C#?

    Great! That works perfect. Thanks DeadEyes.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252

    Re: ChartAt(index) in C#?

    I am actually migrating from VB.NET to C#.NET. So I am new to C# commands. I am trying C# in small methods to familiarize myself with C#.

    For instance..
    Code:
        Private Sub RandomPasswords()
            Dim i%
            Dim pass As String
            Dim passChar As Char
            For i = 1 To 8
                Randomize()
                If Int(Rnd() * 2) = 0 Then
                    passChar = Chr((Rnd() * (57 - 48)) + 48)
                Else
                    passChar = Chr((Rnd() * (90 - 65)) + 65)
                End If
                pass &= passChar
            Next
            txtPassword.Text = pass
            txtPassword.PasswordChar = ""
        End Sub
    I am trying to re-write the above using C#. But I can't find Randomize() or Rnd() or similar statements/funtions in C#. Can you please give me a hand on this too? Much appreciated.

  5. #5
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196

    Re: ChartAt(index) in C#?

    There is a Random Class
    Code:
    const int MAX =10;
    Random r = new Random();
    Console.WriteLine(r.Next(MAX).ToString());
    Console.WriteLine(r.Next(MAX).ToString());
    Console.WriteLine(r.Next(MAX).ToString());

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