https://www.cnblogs.com/Pickuper/articles/2059139.html
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim S1 As String = "图纸名称1"
Dim NewS1 As String = PadRightEx(S1, 20, " ")'用占位符号比较好
Dim S2 As String = "名称A"
Dim NewS2 As String = PadRightEx(S2, 20, " ")
Dim s3 As String = NewS1 & S1 & vbCrLf & NewS2 & S2 & vbCrLf
MsgBox(s3)
End Sub
Private Function PadLeftEx(ByVal str As String, ByVal totalByteCount As Integer, ByVal c As Char) As String
Dim coding As System.Text.Encoding = System.Text.Encoding.GetEncoding("gb2312")
Dim dcount As Integer = 0
For Each ch As Char In str.ToCharArray()
If coding.GetByteCount(ch.ToString()) = 2 Then
System.Math.Max(System.Threading.Interlocked.Increment(dcount), dcount - 1)
End If
Next
Dim w As String = str.PadRight(totalByteCount - dcount, c)
MsgBox(w.Length)
Return w
End Function
Private Function PadRightEx(ByVal str As String, ByVal totalByteCount As Integer, ByVal c As Char) As String
Dim coding As System.Text.Encoding = System.Text.Encoding.GetEncoding("gb2312")
Dim dcount As Integer = 0
For Each ch As Char In str.ToCharArray()
If coding.GetByteCount(ch.ToString()) = 2 Then
dcount = dcount + 2
Else
dcount = dcount + 1
'System.Math.Max(System.Threading.Interlocked.Increment(dcount), dcount - 1)
End If
Next
MsgBox(dcount)
Dim w As String = str.PadRight(totalByteCount - dcount, c)
MsgBox(w.Length)
Return w
End Function
End Class
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |