VB.Net替换不起作用?

jge*_*ost 1 vb.net replace

不确定我是否做错了,基本上我的代码从"111111111"开始,每次线程能够通过在原始数字上加"1"来计数.我希望方法在序列中跳过0,而不是在"111111119"之后转到"111111120",我希望它直接转到"111111121".

    Private Sub IncreaseOne()
    If count < 999999999 Then
        count += 1
    Else
        done = True
    End If
    If CStr(count).Contains("0") Then
        MsgBox("theres a 0 in that...darn.")
        CStr(count).Replace("0", "1")
    End If
    End Sub
Run Code Online (Sandbox Code Playgroud)

*注意,我的消息框会在假设时显示,但是0不会更改为1

Ste*_*eve 7

Replace返回一个带有Replace的效果的字符串,它不起作用....
(记住,在.NET中,字符串是不可变对象)

Dim replaced = CStr(count).Replace("0", "1")
Run Code Online (Sandbox Code Playgroud)

但是,您需要将获取的字符串转换为整数并重新分配给count.

count = Convert.ToInt32(replaced)
Run Code Online (Sandbox Code Playgroud)