请教大家一个字符串截取问题?
各位兄弟请帮个忙,请教大家一个字符串截取问题. 例如定义一个字符串:string str = "abcdABCD4234 "; 怎样截取这个字符串的大写字母,小写字母及空格数...麻烦大家了.. --------------------编程问答-------------------- str.substring(0,4) 小写str.substring(4,4) 大写
--------------------编程问答-------------------- '截取字符串中的大寫,小寫,空格數,數字等等
Public Sub GetSplitNum()
Dim str As String = "abcdABCD4234 "
Dim strSmall As String = "" '小寫
Dim strBig As String = "" '大寫
Dim intSpace As Integer = 0 '空格數
Dim strNum As String = "" '數字
For i As Integer = 0 To str.Length - 1
If Asc(str(i).ToString) >= 97 And Asc(str(i).ToString) <= 122 Then
strSmall = strSmall + str(i).ToString()
ElseIf Asc(str(i).ToString) >= 65 And Asc(str(i).ToString) <= 90 Then
strBig = strBig + str(i).ToString()
ElseIf Asc(str(i).ToString) >= 48 And Asc(str(i).ToString) <= 57 Then
strNum = strNum + str(i).ToString()
ElseIf Asc(str(i).ToString) = 32 Then
intSpace = intSpace + 1
End If
Next --------------------编程问答-------------------- '截取字符串中的大寫,小寫,空格數,數字等等
Public Sub GetSplitNum()
Dim str As String = "abcdABCD4234 "
Dim strSmall As String = "" '小寫
Dim strBig As String = "" '大寫
Dim intSpace As Integer = 0 '空格數
Dim strNum As String = "" '數字
For i As Integer = 0 To str.Length - 1
If Asc(str(i).ToString) >= 97 And Asc(str(i).ToString) <= 122 Then
strSmall = strSmall + str(i).ToString()
ElseIf Asc(str(i).ToString) >= 65 And Asc(str(i).ToString) <= 90 Then
strBig = strBig + str(i).ToString()
ElseIf Asc(str(i).ToString) >= 48 And Asc(str(i).ToString) <= 57 Then
strNum = strNum + str(i).ToString()
ElseIf Asc(str(i).ToString) = 32 Then
intSpace = intSpace + 1
End If
Next
End Sub --------------------编程问答--------------------
--------------------编程问答-------------------- 楼上的判断效率不高啊 --------------------编程问答-------------------- 大家的方法都不错,学习了,谢谢各位了撒! 哈哈! --------------------编程问答-------------------- string str="abcEEDddd";
string str = "abcdABCD4234 ";
int lowSum = 0;
int upSum = 0;
int blankSum = 0;
int numSum = 0;
lowSum = Regex.Replace(str, @"[^a-z]*", "", RegexOptions.Multiline).Length;
upSum = Regex.Replace(str, @"[^A-Z]*", "", RegexOptions.Multiline).Length;
numSum = Regex.Replace(str, @"[^0-9]*", "", RegexOptions.Multiline).Length;
blankSum = Regex.Replace(str, @"[^\s]*", "", RegexOptions.Multiline).Length;
for (int j = 0; j <= str.Length; ++j)
{
char s = str[j];
}
Response.Write(); --------------------编程问答--------------------
string str="abcEEDddd";
for (int j = 0; j <= str.Length; ++j)
{
if(Char.IsUpper(str[j]))判断是否是大写
{....}
else
{.......}
}
补充:.NET技术 , ASP.NET