[.NET] 從字串中取出一段文字(以 byte 為單位)

  • 1796
  • 0

摘要:[.NET] 從字串中取出一段文字(以 byte 為單位)


Function ByteSubString(ByVal str As String, ByVal intStartIndex As Integer, ByVal intEndIndex As Integer, _
							Optional ByVal intCodePage As Integer = 950) As String
	Try
		Dim intLength As Integer = intEndIndex - intStartIndex
		Dim sourceByte As Byte() = System.Text.Encoding.GetEncoding(intCodePage).GetBytes(str)

		Return System.Text.Encoding.GetEncoding(intCodePage).GetString(sourceByte, intStartIndex, intLength)

	Catch ex As Exception
		Throw New Exception(ex.Message)
	End Try

End Function