如何将tOGGLE cASE添加到文本框中,例如,我单击一个按钮,它将文本框中的文本更改为tOGGLE cASE(hello - > hELLO),基本上它需要第一个字母和小写它和其余的上层案例吧。
答案 0 :(得分:2)
这是一种使用.NET Culture函数首先转换为Title Case然后将大小写反转为“tOGGLE cASE”的方法
Private Sub btn_ConvertTotOGGLEcASE_Click(sender As Object, e As EventArgs) Handles btn_ConvertTotOGGLEcASE.Click
'Get the current value of the textbox
Dim MyText As String = MyTextBox.Text
'Convert it to Title Case using built in .NET tools
Dim MyTextInfo As System.Globalization.TextInfo = New System.Globalization.CultureInfo("en-US", False).TextInfo
MyText = MyTextInfo.ToTitleCase(MyText)
'Then invert the case of all the characters
Dim InvertedText As Char() = MyText.Select(Function(c) If(Char.IsLetter(c), If(Char.IsUpper(c), Char.ToLower(c), Char.ToUpper(c)), c)).ToArray()
'Finally convert it back to a string
MyTextBox.Text = New String(InvertedText)
End Sub
答案 1 :(得分:0)
你可以在一个数组中拆分字符串,用lcase(mid(string,1,1)& ucase(mid(string,2,len(string)-1))迭代数组,然后重新组合你的数组在一个字符串
Public function ToogleText(myStr as string) as string
dim str() as string
str = split(myStr," ")
dim toogleStr as string
toogleStr = ""
for each substr as string in str
toogleStr = toogleStr & lcase(mid(substr,1,1)) & ucase(mid(substr, 2,len(substr)-1)) & " "
next substr
if len(toogleStr) > 0 then
ToogleText = mid(toogleStr,1,len(toogleStr)-1)
else
ToogleText =""
end if
end function