[英]How to Replace a String in vb.net
Here's my code: 这是我的代码:
Dim lQuotes As Char = Convert.ToChar(&H201C) ' “
Dim rQuotes As Char = Convert.ToChar(&H201D) ' ”
Dim BP01 As String =
String.Format("<li>{0}<em>{2}</em>{1} ― <strong>{3}</strong></li>", lQuotes, rQuotes, BP1.Text, BPGB1.Text)
Dim objWriter As New System.IO.StreamWriter("d:Temp 1.txt", True)
objWriter.WriteLine(BP01)
objWriter.Close()
If BP1 Textbox is empty, That means If there's no data to input, can we replace it with "Data is empty" word or else with nothing ... like this "" 如果BP1文本框为空,则意味着如果没有数据可输入,我们可以将其替换为“数据为空”一词,否则什么都不要...像这样的“”
For example: 例如:
Replace BP01 to something else so that this line "Data is empty" is displayed 将BP01替换为其他内容,以便显示此行“数据为空”
Note: I don't want to display these html codes like ... < li >, < em > etc. 注意:我不想显示这些HTML代码,例如... <li>,<em>等。
Check your input values and act accordingly instead of replacing 检查您的输入值并采取相应措施,而不是替换
Dim BP01 As String
If (string.IsNullOrWhiteSpace(BP1.Text) Or string.IsNullOrWhiteSpace(BPGB1.Text)) Then
BP01 = "Data Is Empty"
Else
BP01 = String.Format("<li>{0}<em>{2}</em>{1} ― <strong>{3}</strong></li>", lQuotes, rQuotes, BP1.Text, BPGB1.Text)
End If
If you would like to skip output entirely you can just negate ( Not
) both your If
conditions to only act on valid input (BP1 and BPGB1 must not be empty). 如果你想跳过输出完全可以只否定(
Not
)既您If
对有效的输入法仅条件(BP1 和 BPGB1不能为空)。
If (Not string.IsNullOrWhiteSpace(BP1.Text) And Not string.IsNullOrWhiteSpace(BPGB1.Text)) Then
BP01 = String.Format("<li>{0}<em>{2}</em>{1} ― <strong>{3}</strong></li>", lQuotes, rQuotes, BP1.Text, BPGB1.Text)
objWriter.WriteLine(BP01)
End If
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.