
以下是 C# 中 String 类的属性 -
| Sr.No | 属性 &说明 |
|---|---|
| 1 |
Chars 获取当前String对象中指定位置的Char对象。 |
| 2 |
Length 获取当前 String 对象中的字符数。 |
示例
让我们看一个示例 -
1、对ASP内核代码进行DLL封装,从而大大提高了用户的访问速度和安全性;2、采用后台生成HTML网页的格式,使程序访问速度得到进一步的提升;3、用户可发展下级会员并在下级购买商品时获得差额利润;4、全新模板选择功能;5、后台增加磁盘绑定功能;6、后台增加库存查询功能;7、后台增加财务统计功能;8、后台面值类型批量设定;9、后台财务曲线报表显示;10、完善订单功能;11、对所有传输的字符串进行安全
现场演示
using System;
public class Demo {
public static void Main() {
string str1 = "h8b9";
string str2 = "abcdef";
Console.WriteLine("Is string1 null or empty? = "+string.IsNullOrEmpty(str1));
Console.WriteLine("Is string2 null or empty? = "+string.IsNullOrEmpty(str2));
bool val = str1 != str2;
Console.WriteLine("Is str1 equal to str2? = "+val);
for (int i = 0; i < str1.Length; i++) {
if (Char.IsLetter(str1[i]))
Console.WriteLine(""+str1[i]+" is a letter");
else
Console.WriteLine(""+str1[i]+" is a number");
}
}
}输出
这将产生以下输出 -
Is string1 null or empty? = False Is string2 null or empty? = False Is str1 equal to str2? = True h is a letter 8 is a number b is a letter 9 is a number
Example
现在让我们看另一个例子 -
现场演示
using System;
public class Demo {
public static void Main() {
string str1 = "hijklm";
string str2 = String.Empty;
Console.WriteLine("Is string1 null or whitespace? = "+String.IsNullOrWhiteSpace(str1));
Console.WriteLine("Is string2 null or whitespace? = "+String.IsNullOrWhiteSpace(str2));
Console.WriteLine("String1 length = "+str1.Length);
Console.WriteLine("String2 length = "+str1.Length);
Console.WriteLine("String length = "+"demo".Length);
}
}输出
这将产生以下示例 -
Is string1 null or whitespace? = False Is string2 null or whitespace? = True String1 length = 6 String2 length = 6 String length = 4









