62,046
社区成员
发帖
与我相关
我的任务
分享
string str = "MNJDOIkjaldfDVIUAASKFDFDFsdfsdegfdfgh";
StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
foreach (char c in str)
{
if ((int)c < (int)'N')
{
sb1.Append(c);
}
else
{
sb2.Append(c);
}
}
str = sb1.ToString() + 'N' + sb2.ToString();
public string test(string str_text, string str_index)
{
char[] arr = str_text.ToUpper().ToCharArray();
int index = Convert.ToChar(str_index.ToUpper());
var big = arr.Where(x => x > index).Concat(str_index.ToUpper()).Concat(arr.Where(y => y < index)).ToList();
StringBuilder sb = new StringBuilder("");
foreach (char temp in big)
{
sb.Append(temp.ToString());
}
return sb.ToString();
}
最近学习linq...这样写是不是优雅多了0 0
public string test(string str_text, string str_index)
{
char[] arr = str_text.ToUpper().ToCharArray();
int index = Convert.ToChar(str_index.ToUpper());
string max = "";
string min = "";
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] > index)
{
max += arr[i].ToString();
}
if (arr[i] < index)
{
min += arr[i].ToString();
}
}
return max + str_index.ToUpper() + min;
}
第一题吧...这是我的实现...应该没问题吧0 0..
第二题没听懂(基础比较差)...
第三题3楼已经给出答案了...正则匹配每一行...然后每行的对应的group[index/key].value封装成对象 string s = @"{""people"":[
{""firstName"":""Brett"",""lastName"":""Mclaughlin"",""email"":""aaa""},
{""firstName"":""Jhon"",""lastName"":""Hunter"",""email"":""bbb""},
{""firstName"":""Jason"",""lastName"":""Harold"",""email"":""ccc""},]}";
MatchCollection matches = Regex.Matches(s, @"(?is)(?<={""people"":\[.*?){""firstName"":""(?<firstName>[^,]+)"",""lastName"":""(?<lastName>[^,]+)"",""email"":""(?<email>[^,]+)""},(?=.*?\]})");
List<People> peopleList = new List<People>();
foreach (Match match in matches)
{
People people = new People();
people.FirstName = match.Groups["firstName"].Value;
people.LastName = match.Groups["lastName"].Value;
people.Email = match.Groups["email"].Value;
peopleList.Add(people);
}
foreach (People people in peopleList)
Response.Write(string.Format("FirstName:{0}----LastName:{1}----Email:{2}<br/>", people.FirstName, people.LastName, people.Email));