Strings are immutable you cannot set the value of a position in the string. You need to get a char array before you can modify it.
// Get the string as a mutable char array char[] chars = str.ToCharArray(); // Set the character at position 'i' (todo: some range checking) chars[i] = Convert.ToChar(character); // Create a new string based on the modified char array string result = new String(chars); Or you can use a System.Text.StringBuilder which is used to manipulate strings. StringBuilder sb = new StringBuilder(str); sb[i] = Convert.ToChar(character); string result = sb.ToString(); The results of either of these should be the same. Nicko > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > Sent: 19 November 2004 16:59 > To: [email protected] > Subject: RE: Easy C# Help > > Remember string and char are objects. > > Use String.Substring to get a single letter. But you have to > covert it to Char if that is what you need. Just use .ToChar() > > -----Original Message----- > From: Dru Sellers [mailto:[EMAIL PROTECTED] > Sent: Thursday, November 18, 2004 11:15 PM > To: 'Log4NET User'; 'Eric Means' > Subject: OT: Easy C# Help > > I want to do this > > result[i] = System.Convert.ToChar(character); > > How do I do it? > > I am a vb guy and I am used to using > > Mid(RandomString, i, 1) = character > > Thanks, > > Dru > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.797 / Virus Database: 541 - Release Date: 11/15/2004 > > > > > > DISCLAIMER: > This message is intended for the sole use of the addressee, > and may contain information that is privileged, confidential > and exempt from disclosure under applicable law. If you are > not the addressee you are hereby notified that you may not > use, copy, disclose, or distribute to anyone the message or > any information contained in the message. If you have > received this message in error, please immediately advise the > sender by reply email and delete this message. >
