问题描述
我有一个字符串,我想拆分。我正在从数据库中检索这个字符串。我有大约100个字符串,我正在捕获
例如:
\\C-IMS \IMSData \Images\F1231231\3eb8b6e4-9792-4328-a246-0766e205d0a5.JPG
\\C-IMS \IMSData \Images\F5477748 \97cf42d9-3ed1-4d0c-a26d-098e063871e3.JPG
现在我想将每个字符串拆分为\\C-IMS \IMSData \Images \ F1231231和\C-IMS \IMSData \Images \ F5477748。
提前致谢
问候,
richa
Hi ,
I have a string which i want to split.I am retrieving this string from database.I have around 100 strings which i am capturing
for example:
\\C-IMS\IMSData\Images\F1231231\3eb8b6e4-9792-4328-a246-0766e205d0a5.JPG
\\C-IMS\IMSData\Images\F5477748\97cf42d9-3ed1-4d0c-a26d-098e063871e3.JPG
Now I want to split each string upto \\C-IMS\IMSData\Images\F1231231 and \C-IMS\IMSData\Images\F5477748.
Thanks in advance
Regards,
richa
推荐答案
// string[] stringCollection = { .. }
var query = from element in stringCollection
select element.Substring(0, element.LastIndexOf('\\'));
foreach (var item in query)
{
// Further processing could happen here
}
string str=@"\\C-IMS\IMSData\Images\F1231231\3eb8b6e4-9792-4328-a246-0766e205d0a5.JPG";
string str1 = @"\\C-IMS\IMSData\Images\F5477748\97cf42d9-3ed1-4d0c-a26d-098e063871e3.JPG";
string[] strarr=new string[2];
strarr[0] = str;
strarr[1] = str1;
for (int i = 0; i < strarr.Length; i++)
{
string newstr = strarr[i].Substring(0, strarr[i].LastIndexOf('\\'));
MessageBox.Show(newstr);
}
这篇关于如何拆分具有相同公共分隔符的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!