RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
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://scyingshan.cn/article/phpsgj.html