VB.Net 反向器和子字符串
VB.Net Reverser and Substring a string
我有多个带有日期的文件,每个文件的文件名长度不同。
我想剪切字符串以仅获取文件名。
我在 Sql 中的做法是
REVERSE(SUBSTRING(REVERSE('the full file name'), 10, LEN('the full file name')))
示例文件名:
Myfile_20160708
、MyFile123_20160708
、Myfiles12345_20160708
我希望结果是:
Myfile
、MyFile123
、Myfiles12345
如何在 VB.Net 代码中完成它?
像这样。
Dim s As String = "Myfile_20160708"
Dim pos = s.IndexOf("_"c)
If pos >= 0 Then
s = s.Substring(0, pos)
End If
使用IndexOf
查找下划线和子串的位置得到您感兴趣的部分
我有多个带有日期的文件,每个文件的文件名长度不同。 我想剪切字符串以仅获取文件名。
我在 Sql 中的做法是
REVERSE(SUBSTRING(REVERSE('the full file name'), 10, LEN('the full file name')))
示例文件名:
Myfile_20160708
、MyFile123_20160708
、Myfiles12345_20160708
我希望结果是:
Myfile
、MyFile123
、Myfiles12345
如何在 VB.Net 代码中完成它?
像这样。
Dim s As String = "Myfile_20160708"
Dim pos = s.IndexOf("_"c)
If pos >= 0 Then
s = s.Substring(0, pos)
End If
使用IndexOf
查找下划线和子串的位置得到您感兴趣的部分