资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vbnet字符串长度,vb 字符串长度函数

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

遍历每一个字符,看是全角还是半角的。半角的字符总数 +1,全角的字符总数 +2。

10年积累的成都网站设计、成都网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有海宁免费网站建设让你可以放心的选择与我们合作。

参考:

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

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

估计只有在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 如何获得中文字符串的长度?

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

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 格式字符串

没有这种函数,自己做一个函数,效率不会低,因为都是简单运算:

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


分享题目:vbnet字符串长度,vb 字符串长度函数
文章出自:http://cdkjz.cn/article/phpsgj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220