2012年5月1日 下午 04:07
I have the following problem..
I have a string which is hidden i.e. "-----", the string is "hello"
I figure out the second letter is an "e" by using lastIndexof, I then insert "e" in to the position but I am unable to remove the - that was there initially.
int a = words.Word.LastIndexOf(WordGuesses); string b = words.HideWord.Insert(a, WordGuesses); words.HideWord = b;
I have tried remove, using
words.HideWord = words.HideWord.Remove(words.HideWord.Length - 1, 1);
but this just removes the last entry also tried trim.
What I want to do is find the position of the new letter remove the "-" and insert the letter in its place any ideas..?
2012年5月1日 下午 04:14Hmm, not sure what you want to do. String is immutable (), so you cannot change it. Why you jut dont assign a new value to variable?
2012年5月1日 下午 04:18
Thanks for the reply, but I can change the string as its a property but when I do it doesn't remove the '-'.
I want to be able to insert - - - - - "E" in to the second dash, I can do this but I want it to remove the second dash before it adds the "E"
Any more ideas..?
2012年5月1日 下午 04:26
For this you really don't want to be using a string as insert/remove methods are not cheap.
Store both the real word and a char array. The char array will start out with all dashes. Then to change the 2nd position to an 'e' you can simply write out:
myCharArray = 'e';
You can then, at any time, get a string representation of that char array by using:
string someString = new String(myCharArray);
You can use that to set a label, or whatever other means of displaying it you're using.