例を挙げる、A="1あ2い3う4え5
お"
SplitString(A,1,4)="1あ2"
SplitString(A,1,6)="1あ2い"
''' -----------------------------------------------------------------------------
''' <summary>
''' 入力文字列分割
''' </summary>
''' <param name="str">入力文字列</param>
''' <param name="startIndex">ターゲット内の、テキスト置換を開始する文字の位置です。Start は 1 から始まるインデックスです。</param>
''' <param name="len">置き換える文字数を指定します。省略すると、すべての文字列が使用されます。 </param>
''' <returns></returns>
''' <remarks>
''' </remarks>
''' <history>
''' [renzhijia] 2007/07/04 Created
''' </history>
''' -----------------------------------------------------------------------------
Private Function SplitString(ByVal str As String, ByVal startIndex As Integer, ByVal len As Integer) As String
''' <summary>
''' 入力文字列分割
''' </summary>
''' <param name="str">入力文字列</param>
''' <param name="startIndex">ターゲット内の、テキスト置換を開始する文字の位置です。Start は 1 から始まるインデックスです。</param>
''' <param name="len">置き換える文字数を指定します。省略すると、すべての文字列が使用されます。 </param>
''' <returns></returns>
''' <remarks>
''' </remarks>
''' <history>
''' [renzhijia] 2007/07/04 Created
''' </history>
''' -----------------------------------------------------------------------------
Private Function SplitString(ByVal str As String, ByVal startIndex As Integer, ByVal len As Integer) As String
Dim pos As Integer '現在の文字の位置
Dim encoding As System.Text.Encoding
Dim strValue As String 'スプレッドで表示される内容
Dim intStartKeta As Integer 'ファイルに表示される内容の開始位置
Dim splitted As ArrayList '分割された文字列
Dim bytes() As Byte
Dim newbytes() As Byte
Dim intBytes As Integer
Dim enc As System.Text.Encoding
enc = encoding.GetEncoding("SHIFT_JIS")
splitted = New ArrayList
intStartKeta = 0
bytes = enc.GetBytes(str)
strValue = ""
Dim encoding As System.Text.Encoding
Dim strValue As String 'スプレッドで表示される内容
Dim intStartKeta As Integer 'ファイルに表示される内容の開始位置
Dim splitted As ArrayList '分割された文字列
Dim bytes() As Byte
Dim newbytes() As Byte
Dim intBytes As Integer
Dim enc As System.Text.Encoding
enc = encoding.GetEncoding("SHIFT_JIS")
splitted = New ArrayList
intStartKeta = 0
bytes = enc.GetBytes(str)
strValue = ""
Try
If startIndex = 0 Then
startIndex = 1
End If
If bytes.Length < len Then
len = bytes.Length - startIndex + 1
End If
ReDim newbytes(len - 1)
If startIndex = 0 Then
startIndex = 1
End If
If bytes.Length < len Then
len = bytes.Length - startIndex + 1
End If
ReDim newbytes(len - 1)
For intBytes = 0 To len - 1
newbytes(intBytes) = bytes(startIndex - 1 + intBytes)
Next
strValue = enc.GetString(newbytes)
newbytes(intBytes) = bytes(startIndex - 1 + intBytes)
Next
strValue = enc.GetString(newbytes)
Catch ex As Exception
strValue = ""
Finally
End Try
' 文字列型配列として値を返す
Return strValue
End Function
strValue = ""
Finally
End Try
' 文字列型配列として値を返す
Return strValue
End Function