2013年12月12日 星期四
vbnet 字串切割處理函式
本函式主要是要處理中英數 bytes 問題! 條碼機運用
---
Private Function word_substring(ByVal prod_name_str As String, ByVal prod_ptr As Integer) As String
word_substring = prod_name_str
Try
Dim prod_name_A As String = ""
Dim prod_name_B As String = ""
'
Dim chk_ab As Integer = 0
Dim prod_line As Integer = 0
Dim prod_c As String = ""
For i As Integer = 1 To Len(prod_name_str)
prod_c = Asc(Mid(prod_name_str, i, 1))
If prod_c >= 0 And prod_c < 128 Then
prod_line += 1
chk_ab = 1
Else
prod_line += 2
chk_ab = 2
End If
prod_name_A += Mid(prod_name_str, i, 1)
'--
If prod_line >= prod_ptr Then
Select Case prod_line
Case prod_ptr
Case prod_ptr + 1 '加1碼
'words -2 bytes
prod_name_B += Mid(prod_name_A, 1, prod_name_A.Length - 2) + Space(2)
prod_name_B += Mid(prod_name_A, prod_name_A.Length - 1, 2)
prod_name_A = prod_name_B
End Select
prod_line = 0
End If
'--
Next
Return prod_name_A
Catch ex As Exception
Return word_substring
End Try
End Function
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言