vb.net String.StartsWith 方法重载的四种方法实例
时间: 2023-12-10 19:41:13 浏览: 35
1. StartsWith(String) 方法:判断当前字符串是否以指定的字符串开始。
示例代码:
```
Dim str As String = "Hello World"
If str.StartsWith("Hello") Then
Console.WriteLine("字符串以 Hello 开始")
End If
```
输出结果:
```
字符串以 Hello 开始
```
2. StartsWith(Char) 方法:判断当前字符串是否以指定的字符开始。
示例代码:
```
Dim str As String = "Hello World"
If str.StartsWith("H"c) Then
Console.WriteLine("字符串以 H 开始")
End If
```
输出结果:
```
字符串以 H 开始
```
3. StartsWith(String, StringComparison) 方法:判断当前字符串是否以指定的字符串开始,可以指定比较方式。
示例代码:
```
Dim str As String = "Hello World"
If str.StartsWith("hello", StringComparison.OrdinalIgnoreCase) Then
Console.WriteLine("字符串以 hello 开始")
End If
```
输出结果:
```
字符串以 hello 开始
```
4. StartsWith(String, Boolean, CultureInfo) 方法:判断当前字符串是否以指定的字符串开始,可以指定区域性和大小写规则。
示例代码:
```
Dim str As String = "Hello World"
If str.StartsWith("hello", False, CultureInfo.CurrentCulture) Then
Console.WriteLine("字符串以 hello 开始")
End If
```
输出结果:
```
字符串不以 hello 开始
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)