[VB.NET]Removeで文字列の文字を削除する

2021年9月29日

構文
1.位置、文字数を指定して削除
対象文字列.Remove(開始位置、削除文字数)

2.文字を指定して削除
対象文字列.Replace(“削除文字","")

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Module Module1
Sub Main()
Dim str As String = "studyskill"
'開始位置2 削除文字数4
Dim strRv As String = str.Remove(2, 4)
Console.WriteLine("文字を削除する前結果: " + str)
Console.WriteLine("文字を削除する後結果: " + strRv)
'指定文字を削除
Dim strSp As String = str.Replace("study", "")
Console.WriteLine("指定文字を削除: " + strSp)
Console.ReadKey()
End Sub
End Module
Module Module1 Sub Main() Dim str As String = "studyskill" '開始位置2 削除文字数4 Dim strRv As String = str.Remove(2, 4) Console.WriteLine("文字を削除する前結果: " + str) Console.WriteLine("文字を削除する後結果: " + strRv) '指定文字を削除 Dim strSp As String = str.Replace("study", "") Console.WriteLine("指定文字を削除: " + strSp) Console.ReadKey() End Sub End Module
Module Module1

    Sub Main()
        Dim str As String = "studyskill"

        '開始位置2 削除文字数4
        Dim strRv As String = str.Remove(2, 4)
        Console.WriteLine("文字を削除する前結果: " + str)
        Console.WriteLine("文字を削除する後結果: " + strRv)

        '指定文字を削除
        Dim strSp As String = str.Replace("study", "")
        Console.WriteLine("指定文字を削除: " + strSp)

        Console.ReadKey()
    End Sub


End Module

結果
文字を削除する前結果: studyskill
文字を削除する後結果: stkill
指定文字を削除: skill

VB.net

Posted by arkgame