こんにちは、私は表示されたテキストボックス内の各文字の間に 'スペース'を追加する必要があります。C#テキストボックスに 'space'を追加する
彼を推測するために、私は、ユーザーにこの
He__o
ようなマスクされた単語を与えていると私は私がランダムに'_'
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);
で文字を置き換えるために、次のコードを使用しています
にこれを変換したいです
私は試しました:
partialWord[rIndex] = '_ ';
しかし、これはエラー "文字が多すぎます"私は試してみました:
partialWord[rIndex] = "_ ";
これはエラーを返します "タイプ文字列をcharに変換できません。
H e _ _ o
どのように私は各文字間のスペースを達成するために進めることができますか?
おかげ
(私の知る限りでは)重複しますが、あなたをグーグルでのビットではありませんが見つかりましたでしょう:http://stackoverflow.com/questions/7189293/add-spaces-between-the-characters-ofを-a-string-in-javaこれはループをほぼ直接コピーすることができます。 – VinKel