Hi guys, so I need to add a 'space' between each character in my displayed text box.
I am giving the user a masked word like this
He__o
for him to guess and I want to convert this toH e _ _ o
I am using the following code to randomly replace characters with
'_'
char[] partialWord = word.ToCharArray(); int numberOfCharsToHide = word.Length / 2; //divide word length by 2 to get chars to hide Random randomNumberGenerator = new Random(); //generate rand number HashSet<int> maskedIndices = new HashSet<int>(); //This is to make sure that I select unique indices to hide. Hashset helps in achieving this for (int i = 0; i < numberOfCharsToHide; i++) //counter until it reaches words to hide { int rIndex = randomNumberGenerator.Next(0, word.Length); //init rindex while (!maskedIndices.Add(rIndex)) { rIndex = randomNumberGenerator.Next(0, word.Length); //This is to make sure that I select unique indices to hide. Hashset helps in achieving this } partialWord[rIndex] = '_'; //replace with _ } return new string(partialWord);
I have tried :
partialWord[rIndex] = '_ ';
however this brings the error "Too many characters in literal"I have tried :
partialWord[rIndex] = "_ ";
however this returns the error " Cannot convert type string to char.
Any idea how I can proceed to achieve a space between each character?
Thanks