using System;
using System.Collections.Generic;
using System.Text;
namespace StringAndStringBuilder
{
class showString
{
public void shows(string str, int k)
{
//string str = "北京[北]:朝阳[朝],海淀[海],大兴[大];河北省[河北]:保定[保],唐山[唐],张家口[张];湖北[湖]:武汉[武],襄樊[襄]";
if (k == 1)
{
while (str.Contains("["))
{
str = str.Remove(str.IndexOf("["), str.IndexOf("]") - str.IndexOf("[") + 1);
}
str = str.Replace(";", "|");
Console.WriteLine(str);
}
else if (k == 2)
{
string str2 = "";
str = str.Replace("]", "");//将str字符串中所有 ] 替换成空
string[] s = str.Split(";".ToCharArray());
for (int i = 0; i < s.Length; i++)
{
s[i] = s[i].Insert(0, "]");
string str3 = s[i];
for (int j = 0; j < str3.Length - 1; j++)
{
if (str3[j] == ','|| str3[j]==':')
{
str3= str3.Insert(j+1, "]");
}
}
str2 += str3+";";
}
while (str2.Contains("]"))
{
str2 = str2.Remove(str2.IndexOf("]"), str2.IndexOf("[") - str2.IndexOf("]") + 1);
}
str2 = str2.Replace(";", "|");
str2 = str2.Remove(str2.Length - 1);
Console.WriteLine(str2);
}
}
}
}