「VB.NET」Midで指定位置からの文字列を返す

2021年9月14日

構文
Public Function Mid (str As String, Start As Integer, Length As Integer) As String
文字列の指定の位置から始まる指定の数の文字を含む文字列を返します。
Start  返す文字の開始位置
Length 返される文字数
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Module Module1
Sub Main()
' String型文字列変数の宣言.
Dim tarStr As String = "Study Skill in arkgame .com"
' 指定位置1 文字数3
Dim resWd As String = Mid(tarStr, 1, 5)
Console.WriteLine(resWd)
' 指定位置14 文字数4の文字列を返す
Dim resultWord As String = Mid(tarStr, 16, 7)
Console.WriteLine(resultWord)
' 指定位置5から文字列を返す
Dim resultWords As String = Mid(tarStr, 6)
Console.WriteLine(resultWords)
Console.ReadKey()
End Sub
End Module
Module Module1 Sub Main() ' String型文字列変数の宣言. Dim tarStr As String = "Study Skill in arkgame .com" ' 指定位置1 文字数3 Dim resWd As String = Mid(tarStr, 1, 5) Console.WriteLine(resWd) ' 指定位置14 文字数4の文字列を返す Dim resultWord As String = Mid(tarStr, 16, 7) Console.WriteLine(resultWord) ' 指定位置5から文字列を返す Dim resultWords As String = Mid(tarStr, 6) Console.WriteLine(resultWords) Console.ReadKey() End Sub End Module
Module Module1


    Sub Main()
        ' String型文字列変数の宣言.
        Dim tarStr As String = "Study Skill in arkgame .com"

        ' 指定位置1 文字数3
        Dim resWd As String = Mid(tarStr, 1, 5)
        Console.WriteLine(resWd)

        ' 指定位置14 文字数4の文字列を返す 
        Dim resultWord As String = Mid(tarStr, 16, 7)
        Console.WriteLine(resultWord)

        ' 指定位置5から文字列を返す 
        Dim resultWords As String = Mid(tarStr, 6)
        Console.WriteLine(resultWords)

        Console.ReadKey()

    End Sub

End Module

実行結果
Study
arkgame
Skill in arkgame .com

VB.net

Posted by arkgame