Dom*_*zic 0 c# split lastindexof
我需要将文件名分成两个字符串的数组。
文件名如下所示:IMG-20190604-WA0005.jpg
我想要的数组:
[0] =“IMG-20190604-WA0005”
[1] =“jpg”
我使用索引位置LasIndexOf('.')
不要使用字符串方法,而使用以下中的可用方法System.IO.Path:
string file = "IMG-20190604-WA0005.jpg";
string filenameWithoutExtension = Path.GetFileNameWithoutExtension(file);
string extension = Path.GetExtension(file);
Run Code Online (Sandbox Code Playgroud)
如果您不想要 . 一开始,将其删除:
string extension = Path.GetExtension(file).TrimStart('.');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
98 次 |
| 最近记录: |