急求vb原来的LeftB()函数在vb.net中应该怎么写?
急求vb原来的LeftB()函数升级到vb.net中应该怎么写?
[解决办法]
'*******************************************************************************
'* @outline Charを処理
'* @author エイジス株式会社
'* @revision 2007/01/5 エイジス大連 張立寧
'*******************************************************************************
Public Function RightB(ByVal p_Value As String, ByVal p_Length As Integer) As String
Dim Int_Leng As Integer
Try
RightB = " "
Int_Leng = LenB(p_Value)
If Int_Leng <= 0 Then
Exit Try
End If
If Int_Leng - p_Length < 0 Then
RightB = MidB(p_Value, 1, Int_Leng)
Else
RightB = MidB(p_Value, Int_Leng - p_Length + 1, p_Length)
End If
Catch ex As Exception
End Try
End Function
'********************************************************
'LeftBと同等の処理
'********************************************************
Public Function LeftB(ByVal p_Value As String, ByVal p_Length As Integer) As String
Try
LeftB = " "
LeftB = MidB(p_Value, 1, p_Length)
Catch ex As Exception
End Try
End Function
'********************************************************
'MidBと同等の処理
'********************************************************
Public Function MidB(ByVal p_Value As String, ByVal p_Start As Integer, ByVal p_Length As Integer) As String
Dim TargetEncoding As System.Text.Encoding
Dim encodedChars() As Byte
Dim buf() As Byte
Dim Int_Leng As Integer
Try
MidB = " "
TargetEncoding = System.Text.Encoding.GetEncoding( "Shift-jis ")
encodedChars = TargetEncoding.GetBytes(p_Value)
If p_Start > encodedChars.Length Then
Exit Try
End If
If p_Start + p_Length > encodedChars.Length Then
Int_Leng = encodedChars.Length - p_Start + 1
Else
Int_Leng = p_Length
End If
ReDim buf(Int_Leng - 1)
System.Array.Copy(encodedChars, p_Start - 1, buf, 0, Int_Leng)
Return TargetEncoding.GetString(buf)
Catch ex As Exception
End Try
End Function
'********************************************************
'代替LenB処理
'********************************************************
Public Function LenB(ByRef strBuf As String) As Integer
Dim TargetEncoding As System.Text.Encoding
Dim encodedChars() As Byte
Try
LenB = 0
If strBuf = " " Then
Exit Try
End If
TargetEncoding = System.Text.Encoding.GetEncoding(932)
encodedChars = TargetEncoding.GetBytes(strBuf)
LenB = encodedChars.Length
Catch ex As Exception
End Try
End Function
'********************************************************
' 機能
' ある文字列(String1)の中から指定した文字列(String2)を検索し、最初に見つかった位置を返す。
' 引数
' String1 必ず指定します。検索する文字列型 (String) の式を指定します。
' String2 必ず指定します。検索する文字列型 (String) の式を指定します。
' 戻り値
' String1 が長さ 0 の文字列 ( " ") または Nothing のとき 戻り値 :0
' String2 が長さ 0 の文字列 ( " ") または Nothing のとき 戻り値 :0
' String2 が見つからないとき 戻り値 :0
' String2 が String1 内で見つかったとき 戻り値 :一致する文字列の開始位置
'
'********************************************************
Public Function InstrB(ByVal String1 As String, ByVal String2 As String) As Integer
Dim MatchPos As Integer
Try
MatchPos = 0
MatchPos = InStr(1, String1, String2, CompareMethod.Binary)
If (String2 Is Nothing) Or (String2 = " ") Then
MatchPos = 0
End If
Return MatchPos
Catch ex As Exception
End Try
End Function