|
-
Dec 17th, 2004, 01:32 AM
#1
Thread Starter
Addicted Member
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
-
Dec 17th, 2004, 04:00 AM
#2
Re: ChartAt(index) in C#?
Try this:
Code:
string str = "hello world";
Console.WriteLine( str[0] ); //returns "h";
Console.WriteLine( str[2] ); //returns "l";
-
Dec 17th, 2004, 08:48 PM
#3
Thread Starter
Addicted Member
Re: ChartAt(index) in C#?
Great! That works perfect. Thanks DeadEyes.
-
Dec 17th, 2004, 08:57 PM
#4
Thread Starter
Addicted Member
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.
-
Dec 18th, 2004, 09:09 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|