I_R_Lee Posted October 9, 2002 Posted October 9, 2002 How would I avoid that error? It happens on this line of code: txtWord.Text = Replace$(txtWord.Text.Chars(I), txtWord.Text.Chars(I), "*") I've also tried txtWord.Text = Replace$(txtWord.Text, txtWord.Text.Chars(I), "*") but I get the same error. Any help? Quote
I_R_Lee Posted October 9, 2002 Author Posted October 9, 2002 Never mind, I just found the StringBuilder class, and that allows it! Quote
I_R_Lee Posted October 10, 2002 Author Posted October 10, 2002 Actually, I do need help. I get that error on these lines instead: Dim SB As New System.Text.StringBuilder(CurWord) Dim SBW As New System.Text.StringBuilder(txtWord.Text) Dim SBG As New StringBuilder(txtGuess.Text) For I = 0 To SB.Length ' Here If SB(I) = SBG(I) Then ' Here txtWord.Text = Replace(SBW(I), SB(I), SBG(I), 1, I) ' and here End If Next How do I stop that? Or at least, how do you replace individual characters? Quote
*Gurus* divil Posted October 10, 2002 *Gurus* Posted October 10, 2002 It should almost certainly be, For I = 0 To SB.Length - 1 Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
I_R_Lee Posted October 10, 2002 Author Posted October 10, 2002 Thanks, that fixed the first line but the other two still give the same error. Quote
*Gurus* Derek Stone Posted October 10, 2002 *Gurus* Posted October 10, 2002 You're trying to access elements of a variable which isn't an array. Quote Posting Guidelines
I_R_Lee Posted October 11, 2002 Author Posted October 11, 2002 Is there a way to replace individual characters e.g Dim This As String = "ThisThis" Dim That As String = "ThatThat" txtWord.Text = This & That For I = 0 To txtWord.Text - 1 txtWord.Text = Replace(txtWord.Text, This.Chars(I), That.Chars(I+1)) Next Something like that, is it possible, if not, how would it be done with the string builder class? Quote
*Gurus* Derek Stone Posted October 11, 2002 *Gurus* Posted October 11, 2002 Coerce the string into a byte array using System.Text.Encoding.GetBytes(). Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.