vb.net字符串的长度 vb 字符串长度

VB.net 如何获得中文字符串的长度?

上面思路是正确的, 用ascw 函数也可以

目前创新互联公司已为上1000家的企业提供了网站建设、域名、雅安服务器托管绵阳服务器托管、企业网站设计、西林网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

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怎样定义定长字符串?急!!!!!深圳

摘自帮助文档,我也不是很理解

估计只有在Visual Basic 文件输入和输出才有用

示例

Visual Basic 复制代码

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 是信息性的属性,不能用于将可变长度字符串转换为固定长度字符串。此属性的作用是修改那些识别 VBFixedStringAttribute 的方法或 API 调用(如 Len 和 FilePut 函数)使用结构中的字符串以及非局部变量的方式。请记住,此属性不会更改字符串本身的实际长度。

备注

默认情况下,Visual Basic 字符串为可变长度的字符串。在使用 Visual Basic 文件输入和输出函数(如需要固定长度字符串的 FileGet 和 FilePut)时,该属性非常有用。

注意

VBFixedStringAttribute 属性以字节而不是字符为单位指定字符串长度。

vb.net怎样定义定长字符串?急!!!!!

摘自帮助文档,我也不是很理解

估计只有在Visual Basic 文件输入和输出才有用

示例

Visual Basic 复制代码

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 是信息性的属性,不能用于将可变长度字符串转换为固定长度字符串。此属性的作用是修改那些识别 VBFixedStringAttribute 的方法或 API 调用(如 Len 和 FilePut 函数)使用结构中的字符串以及非局部变量的方式。请记住,此属性不会更改字符串本身的实际长度。

备注

默认情况下,Visual Basic 字符串为可变长度的字符串。在使用 Visual Basic 文件输入和输出函数(如需要固定长度字符串的 FileGet 和 FilePut)时,该属性非常有用。

注意

VBFixedStringAttribute 属性以字节而不是字符为单位指定字符串长度。

VB.Net如何测量含有中文的字符串长度

遍历每一个字符,看是全角还是半角的。半角的字符总数 +1,全角的字符总数 +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


当前标题:vb.net字符串的长度 vb 字符串长度
链接URL:http://csdahua.cn/article/dospsss.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流