Vb.net VB 2010-用破折号替换字符串的所有字母
VB 2010-这里是初学者, 我正在为一项任务创建一个刽子手游戏,我在用破折号替换字符串文本时遇到了问题。我不确定是否需要将字符串转换为字符数组,或者是否可以使用string.Replace函数。我知道我需要循环它不确定如何 我非常困惑,我需要一些帮助。在我学习的过程中,请尽量保持简单和理性 到目前为止,我的沙盒代码:Vb.net VB 2010-用破折号替换字符串的所有字母,vb.net,visual-studio-2010,Vb.net,Visual Studio 2010,VB 2010-这里是初学者, 我正在为一项任务创建一个刽子手游戏,我在用破折号替换字符串文本时遇到了问题。我不确定是否需要将字符串转换为字符数组,或者是否可以使用string.Replace函数。我知道我需要循环它不确定如何 我非常困惑,我需要一些帮助。在我学习的过程中,请尽量保持简单和理性 到目前为止,我的沙盒代码: Imports System.IO Public Class Form1 Private Const TEST = "test.txt" Private
Imports System.IO
Public Class Form1
Private Const TEST = "test.txt"
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim WordString As String = Nothing
Dim NewWordInteger As Integer
Dim RandomWord As New Random(System.DateTime.Now.Millisecond) 'Load a new word at the time it was initiated
'Load words from test file into the array
Dim WordArray() As String = File.ReadAllLines(TEST) 'Reads words from list and declares each as a string
'Select Random word from the number of words in the dictionary.txt file
NewWordInteger = RandomWord.Next(0, 4)
'Display RandomWord in textbox as STRING..
WordString = WordArray(NewWordInteger) ' Assigns wordstring a word from the arrany & random by the NewWordInterger Substring..
WordDisplayTextBox.Text = WordString ' will display the word in the textbox
SolveLabel.Text = WordString ' will display the word in the Solve label
'Will shoe the array word and the word/string position in the TEST.file
ListBox1.Items.Add(WordString) ' will show the word
ListBox2.Items.Add(NewWordInteger) ' will show the string position in the TEST.file
'search string and replace letters with _ (Dashes)
Dim charArray() As Char = WordDisplayTextBox.Text.ToCharArray
For Each item As Char In WordDisplayTextBox.Text
WordDisplayTextBox.Text = WordString.Replace(item, "_")
Next
End Sub
End Class
如果要用破折号替换字符串中的所有字符,为什么不创建一个仅由破折号组成的新字符串,其长度与起始字符串相同?这不是一回事吗
WordDisplayTextBox.Text = New String("_", WordString.Length)
如果要用破折号替换字符串中的所有字符,为什么不创建一个仅由破折号组成的新字符串,其长度与起始字符串相同?这不是一回事吗
WordDisplayTextBox.Text = New String("_", WordString.Length)
循环遍历WordString的长度,每次在WordDisplayTextBox中写入
For i As Integer = 1 To Len(txtWordString.Text)
WordDisplayTextBox.Text += "__" + " " 'Space separates the dashes for clarity
Next
循环遍历WordString的长度,每次在WordDisplayTextBox中写入
For i As Integer = 1 To Len(txtWordString.Text)
WordDisplayTextBox.Text += "__" + " " 'Space separates the dashes for clarity
Next
我一直在努力寻找如何在vb.net中实现这一点。如果我没有弄错的话,在旧的VB中,有一个特定的函数来执行此操作,我正在Microsoft.VisualBasic.Strings命名空间中查找它…:如果它在那里,它可能已经被正则表达式所取代。你可能会做一些类似Regex'a-z,'a-z',0-9或类似的事情,但你对Regex不太了解,但对初学者来说,这可能是太过分了。。。当它做一个连续的破折号时,它就可以工作了,比如:________;它需要它显示为例如word,_____;它为什么我认为t必须循环?还有ajakblackgoat你怎么用的,发现VB6函数做的一样,更简单。。。Stringlength,我的例子中的字符?我一直在努力寻找如何在vb.net中实现这一点。如果我没有弄错的话,在旧的VB中,有一个特定的函数来执行此操作,我正在Microsoft.VisualBasic.Strings命名空间中查找它…:如果它在那里,它可能已经被正则表达式所取代。你可能会做一些类似Regex'a-z,'a-z',0-9或类似的事情,但你对Regex不太了解,但对初学者来说,这可能是太过分了。。。当它做一个连续的破折号时,它就可以工作了,比如:________;它需要它显示为例如word,_____;它为什么我认为t必须循环?还有ajakblackgoat你怎么用的,发现VB6函数做的一样,更简单。。。Stringlength,我的示例中的字符?