我有一個字符串,我想通過替換它的不同部分來更改爲新版本。
比方說,我有這個字符串:C# - 一次替換字符串的兩個不同部分
My=name,My=surname
,我要返回:
name.surname
所以我想取代我的兩個與""
和,
與.
。可能嗎?
我有一個字符串,我想通過替換它的不同部分來更改爲新版本。
比方說,我有這個字符串:C# - 一次替換字符串的兩個不同部分
My=name,My=surname
,我要返回:
name.surname
所以我想取代我的兩個與""
和,
與.
。可能嗎?
str = str.Replace("My=", "").Replace(",", ".");
那麼,如果你能保證名字或姓氏都不包含字符串「我的」,那麼Tim的回答是正確的。但是,如果「姓名」或「姓氏」包含字符串「我的」更復雜
string input = "My=Steve,My=Myland";
StringBuilder sb = new StringBuilder();
string[] parts = input.Split(',');
foreach (string p in parts)
{
string[] subs = p.Split('=');
sb.Append(subs[1] + ".");
}
if(sb.Length > 0) sb.Length--;
Console.WriteLine(sb.ToString());
是這個vb或c#? – BugFinder
名稱或姓氏是否有可能包含子字符串「我的」? – Steve
VB和C#是不同的語言 – user1666620