VB.Net 替换不起作用? [英] VB.Net Replace not working?

查看:47
本文介绍了VB.Net 替换不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Not sure if I'm doing something wrong or not, basically my code starts at "111111111" and counts up by adding "1" to the original number every time the thread is able to. I want the method to skip 0's in the sequence though, instead of going to "111111120" after "111111119" I would like it to go straight to "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

*注意,我的消息框在它应该显示的时候显示,但是,0s 没有变成 1s

*note, my message box displays when it is suppose to but, 0s are not changed to 1s

推荐答案

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

Replace returns a string with the effects of the Replace, It doesn't work in place....
(Remember, in NET the strings are immutable objects)

Dim replaced = CStr(count).Replace("0", "1")

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

However you need to convert the string obtained to an integer and reassign to count.

count = Convert.ToInt32(replaced)

这篇关于VB.Net 替换不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆