變長字符串最多可包含大約 20 億 ( 2^31)個字符。

創(chuàng)新互聯(lián)建站是一家集網(wǎng)站建設(shè),會寧企業(yè)網(wǎng)站建設(shè),會寧品牌網(wǎng)站建設(shè),網(wǎng)站定制,會寧網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,會寧網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。
定長字符串可包含 1 到大約 64K ( 2^16 ) 個字符。
希望對樓主有幫助
摘自幫助文檔,我也不是很理解
估計只有在Visual Basic 文件輸入和輸出才有用
示例
Visual Basic 復(fù)制代碼
Structure Person
Public ID As Integer
Public MonthlySalary As Decimal
Public LastReviewDate As Long
VBFixedString(15) Public FirstName As String
VBFixedString(15) Public LastName As String
VBFixedString(15) Public Title As String
VBFixedString(150) Public ReviewComments As String
End Structure
注意
VBFixedStringAttribute 是信息性的屬性,不能用于將可變長度字符串轉(zhuǎn)換為固定長度字符串。此屬性的作用是修改那些識別 VBFixedStringAttribute 的方法或 API 調(diào)用(如 Len 和 FilePut 函數(shù))使用結(jié)構(gòu)中的字符串以及非局部變量的方式。請記住,此屬性不會更改字符串本身的實際長度。
備注
默認情況下,Visual Basic 字符串為可變長度的字符串。在使用 Visual Basic 文件輸入和輸出函數(shù)(如需要固定長度字符串的 FileGet 和 FilePut)時,該屬性非常有用。
注意
VBFixedStringAttribute 屬性以字節(jié)而不是字符為單位指定字符串長度。
→
沒有這種函數(shù),自己做一個函數(shù),效率不會低,因為都是簡單運算:
Function FillString(ByVal a As String, ByVal b As String, ByVal c As Integer) As String
If a.Length c Then
Return a + StrDup(c - a.Length, b)
Else
Return Mid(a, 1, c)
End If
End Function
摘自幫助文檔,我也不是很理解
估計只有在Visual Basic 文件輸入和輸出才有用
示例
Visual Basic 復(fù)制代碼
Structure Person
Public ID As Integer
Public MonthlySalary As Decimal
Public LastReviewDate As Long
VBFixedString(15) Public FirstName As String
VBFixedString(15) Public LastName As String
VBFixedString(15) Public Title As String
VBFixedString(150) Public ReviewComments As String
End Structure
注意
VBFixedStringAttribute 是信息性的屬性,不能用于將可變長度字符串轉(zhuǎn)換為固定長度字符串。此屬性的作用是修改那些識別 VBFixedStringAttribute 的方法或 API 調(diào)用(如 Len 和 FilePut 函數(shù))使用結(jié)構(gòu)中的字符串以及非局部變量的方式。請記住,此屬性不會更改字符串本身的實際長度。
備注
默認情況下,Visual Basic 字符串為可變長度的字符串。在使用 Visual Basic 文件輸入和輸出函數(shù)(如需要固定長度字符串的 FileGet 和 FilePut)時,該屬性非常有用。
注意
VBFixedStringAttribute 屬性以字節(jié)而不是字符為單位指定字符串長度。
遍歷每一個字符,看是全角還是半角的。半角的字符總數(shù) +1,全角的字符總數(shù) +2。
參考:
Public?Function?GetByteLength(ByVal?value?As?String)?As?Long
Dim?i?As?Long?=?0
For?Each?c?As?Char?In?value
If?(c.ToString().Length?=?System.Text.Encoding.Default.GetByteCount(value.ToString()))?Then
i?=?i?+?1
End?If
i?=?i?+?1
Next
Return?i
End?Function
上面思路是正確的, 用ascw 函數(shù)也可以
private function LenC( ps as string ) as Integer
Dim n As Integer
Dim StrLen As Integer
For n = 1 To Len(Text1.Text)
If Ascw(Mid(Text1.Text, n, 1)) 256 Then
StrLen = StrLen + 2
Else
StrLen = StrLen + 1
Next n
return strLen
end function
分享名稱:vb.net字符串長度,vb string 長度
分享URL:http://www.yijiale78.com/article22/dschdcc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、云服務(wù)器、用戶體驗、網(wǎng)站排名、微信公眾號、
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)