Select 一切来自 //
Select everything from //
我正在制作 Visual Basic 中的 "mini programming language"。
主要是为了练习和娱乐。
我只有一个问题。我想做一个评论系统。
我知道它是如何工作的,但我不知道该怎么做。
这就是我想要做的:
我想从 // 开始 select 所有文本
例如,如果我写:
print = "Hello World!"; //This is a comment!
它将 select 来自 // 的所有内容,因此它将 select
//This is a comment!
然后我会把 selected 的文本替换成空的。
您可以使用 String.IndexOf
+ Substring
:
Dim code = "Dim print = ""Hello World!""; //This is a comment!"
Dim indexOfComment = code.IndexOf("//")
Dim comment As String = Nothing
If indexOfComment >= 0 Then comment = code.Substring(indexOfComment)
如果您想要评论之前的部分,请不要使用 String.Replace
,还要使用 Substring
或 Remove
:
code.Substring(0, indexOfComment)
我正在制作 Visual Basic 中的 "mini programming language"。 主要是为了练习和娱乐。 我只有一个问题。我想做一个评论系统。 我知道它是如何工作的,但我不知道该怎么做。
这就是我想要做的: 我想从 // 开始 select 所有文本 例如,如果我写:
print = "Hello World!"; //This is a comment!
它将 select 来自 // 的所有内容,因此它将 select
//This is a comment!
然后我会把 selected 的文本替换成空的。
您可以使用 String.IndexOf
+ Substring
:
Dim code = "Dim print = ""Hello World!""; //This is a comment!"
Dim indexOfComment = code.IndexOf("//")
Dim comment As String = Nothing
If indexOfComment >= 0 Then comment = code.Substring(indexOfComment)
如果您想要评论之前的部分,请不要使用 String.Replace
,还要使用 Substring
或 Remove
:
code.Substring(0, indexOfComment)