共用方式為


HOW TO:移除部分字串 (Visual Basic)

更新:2007 年 11 月

下列程式碼範例會將某個字串從其他字串中移除。

範例

這個範例會使用 Replace 函式,將每一個出現的子字串取代成空字串。結果會是已移除子字串的新字串。

這個範例會將 Replace 函式的傳回值指派給字串變數 withoutParts。儲存在 withParts 的原始字串不會變更。

Dim withParts As String = "Books and Chapters and Pages"
Dim withoutParts As String = Replace(withParts, "and ", "")

編譯程式碼

將 "Books and Chapters and Pages" 換成您要操作的字串。

請參閱

參考

Replace 函式 (Visual Basic)

String 資料型別 (Visual Basic)