替换(var1,var2,"")将无法使用VB.NET [英] Replace(var1, var2, " ") won't work VB.NET
本文介绍了替换(var1,var2,"")将无法使用VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想取消选中该复选框以删除变量上的文字
I want when the checkbox is unchecked to delete text off a variable
Imports System
Imports System.IO
Imports System.Text
Imports System.Environment
Public Class Form1
Dim slowchecked As Boolean = False
Dim filepath As String
Dim code1 As String = ""
Dim slowdown As String
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
If slowchecked = False Then
slowdown = ("start" & NewLine & "start" & NewLine & "start" & NewLine & "start" _
& NewLine & "start" & NewLine & "start" & NewLine & "start crash" & NewLine)
code1 = (code1 & slowdown)
slowchecked = True
ElseIf slowchecked = True Then
Replace(code1, slowdown, "")
MsgBox(code1)
slowchecked = False
End If
End Sub
End Class
但它不会删除或出现错误
我尝试过:
尝试交换替换(代码1,减速,)用code1.Replace(slowdown,),但我不知道是什么否则试试。
but it doesn't delete or come out with an error
What I have tried:
Tried swapping "Replace(code1, slowdown, "")" with "code1.Replace(slowdown, "")" but I don't know what else to try.
推荐答案
是的。但不是你假设它的方式。
替换不会改变字符串,它返回一个新的字符串,替换完成:替换函数(VB6) - VB&果壳中的VBA:语言[书籍] [ ^ ]
因此您需要将结果分配给变量,否则它就会被丢弃。
顺便说一下:如果你打算使用VB.NET,那么你应该停止使用VB6等函数,比如Replace和MsgBox,而是使用.NET版本:String.Replace Method(System)| Microsoft Docs [ ^ ]和 MessageBox.Show方法(System.Windows)| Microsoft Docs [ ^ ]
Yes it does. But not the way you are assuming it would.
Replace doesn't change strings, it returns a new string with the replacements done: Replace Function (VB6) - VB & VBA in a Nutshell: The Language [Book][^]
So you need to assign the result to a variable, or it is just discarded.
By the way: if you are going to use VB.NET, then you should stop using VB6 functions such as Replace and MsgBox, and use the .NET versions instead: String.Replace Method (System) | Microsoft Docs[^] and MessageBox.Show Method (System.Windows) | Microsoft Docs[^]
这篇关于替换(var1,var2,"")将无法使用VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文