How does the string replace function in VB.net not work?

后端 未结 6 528
生来不讨喜
生来不讨喜 2020-12-11 05:06

I wrote up some code. The code is shown below. The first part is to read a html into string format. The second part is to search a mark in the string and replace the string

6条回答
  •  温柔的废话
    2020-12-11 05:18

    Strings are immutable, that means once they are created you cannot modify them. So you have to create a new one and assign that to your string variable:

    TempText = TempText.Replace("the_key_string", "replace_by_this_string")
    

    MSDN: String Data Type (Visual Basic):

    Once you assign a string to a String variable, that string is immutable, which means you cannot change its length or contents. When you alter a string in any way, Visual Basic creates a new string and abandons the previous one. The String variable then points to the new string.

提交回复
热议问题