你好我只是想知道是否有反向这个代码,以便第一个字母是小写的,其余的单词是大写?
Dim s As String = "the quick brown fox jumps over the lazy dog"
Dim s2 As String = StrConv(s, VbStrConv.ProperCase)
MessageBox.Show(s2)
我正在使用.net frameworks 3.5
这是答案!谢谢蒂姆!
Dim s As String = TextBox1.Text
Dim s2 = String.Join(" ", s.Split() .Select(Function(w)UppercaseAllButFirst(w)).ToArray())
TextBox2.Text = s2
答案 0 :(得分:1)
您可以创建一个新功能:
Public Shared Function UppercaseAllButFirst(s As String) As String
' check for empty string
If (String.IsNullOrEmpty(s)) Then
Return String.Empty
End If
Return Char.ToLower(s(0)) & s.Substring(1).ToUpper()
End Function
然后你可以这样使用它:
Dim s2 = String.Join(" ", s.Split().Select(Function(w) UppercaseAllButFirst(w)))
.NET 3.5,String.Join
需要一个数组:
String.Join(" ", s.Split().Select(Function(w) UppercaseAllButFirst(w)).ToArray())
答案 1 :(得分:1)
你可以这样做:
dim s1 as string="the quick brown fox jumps over the lazy dog"
dim s2 as string= _
string.Join(" ",s1.Split(" ").Select (function(s) _
s.Substring(0,1).ToLower()+s.Substring(1).ToUpper()).ToArray())
这将为您提供此输出:
tHE qUICK bROWN fOX jUMPS oVER tHE lAZY dOG