VB 2010 - 초보자, 과제에 행맨 게임을 만들고 대시로 문자열의 텍스트를 바꾸는 데 문제가 있습니다. 문자열을 charArray()로 변환해야하는지 또는 string.Replace 함수를 사용할 수 있는지 확실하지 않습니다. 어떻게해야할지 모르겠다. ..VB 2010 - 문자열의 모든 문자를 대시로 바꿉니다
나는 약간의 도움이 필요하다. 내가 배우는 동안 이유와 함께 간단하게 노력하십시오. 지금까지
내 샌드 박스 코드 : 당신이 대시 문자열의 모든 문자를 바꾸려면
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
내부 때마다 쓰기 "__"을 통해. 만약 내가 잘못 생각하지 않는다면, 오래된 VB에서 이것을 수행하는 특정 함수가 있었고 Microsoft.VisualBasic.Strings 네임 스페이스에서 찾고있었습니다 ... :) – ajakblackgoat
만약 거기에 있다면 Regex로 대체되었을 것입니다. 아마도 Regex ('-z,'A-Z ', 0-9) 또는 그 라인을 따라 뭔가 (Regex도 잘 모르겠다)와 같은 것을 할 수는 있지만 어쨌든 초보자에게는 과도한 방법 일 것입니다. – AFischbein
VB6 함수가 동일하고 쉽게 ... [String (length, character)'] (http://en.wikibooks.org/wiki/Visual_Basic/VB6_Command_Reference#String) – ajakblackgoat