C# 需要帮助从给定字符串获取子字符串吗
我在应用程序中有以下字符串 字符串s=。\abc_xyz\drff\dsqa_license_db\dgfx\xsad_license_db.rfds-17343 我需要上面字符串中的子字符串作为。\abc\u xyz\drff\ 请帮我做到这一点 谢谢C# 需要帮助从给定字符串获取子字符串吗,c#,string,split,C#,String,Split,我在应用程序中有以下字符串 字符串s=。\abc_xyz\drff\dsqa_license_db\dgfx\xsad_license_db.rfds-17343 我需要上面字符串中的子字符串作为。\abc\u xyz\drff\ 请帮我做到这一点 谢谢string s=@“\abc_xyz\drff\dsqa_license\u db\dgfx\xsad_license\u db.rfds-17343”; 字符串[]splitChar={@“\”}; int=3; string[]splitS
string s=@“\abc_xyz\drff\dsqa_license\u db\dgfx\xsad_license\u db.rfds-17343”;
字符串[]splitChar={@“\”};
int=3;
string[]splitString=s.Split(splitChar、StringSplitOptions.removeMptyEntries);
StringBuilder sb=新的StringBuilder();
for(int i=0;i
标准是什么?您自己尝试过什么?这个问题以前已经回答过很多次了,通过简单的网络搜索很容易找到答案。提示:String.Substring(0,14)
正如Selman22所说,您如何知道这是您想要的字符串?前15个字符?从开头到第三个“\”字符的所有内容?标准是什么?creteria是我想从第一个斜杠上拆分第三个斜杠上的字符串
string s = @".\abc_xyz\drff\dsqa_license_db\dgfx\xsad_license_db.rfds-17343";
string[] splitChar = { @"\"};
int yourCriteria = 3;
string[] splitString = s.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < yourCriteria; i++)
{
if (sb.Length == 0)
sb.AppendFormat("{0}", splitString[i]);
else
sb.AppendFormat(@"\{0}", splitString[i]);
}
//now do whatever you want to with sb.ToString();