【发布时间】:2014-02-26 03:22:55
【问题描述】:
伙计们,我正在从以下查询中获取数据
MySqlCommand cmd = new MySqlCommand("select concat(c1.countryname,' vs ',c2.countryname) as CountryACountryB,r.Description as Round,m.result,m.matchId from matches m left join countries c1 on m.countryId1=c1.countryId left join countries c2 on m.countryId2=c2.countryId left join rounds r on m.roundId=r.roundId where matchId=" + msMatch.SelectedItem.Value, register);
当我检查 i Value 进入 CountryACountryB 时,它的阿根廷与波斯尼亚和黑塞哥维那(例如:)
这是我实现的分割字符串的代码
string fullTeam = dr["CountryACountryB"].ToString();
string[] names = fullTeam.Split(' ', '-');
string name = names.First();
string lasName = names.Last();
string Final = name + ". " + lasName;
它确实有效,但在阿根廷对波斯尼亚和黑塞哥维那的比赛中
string name = names.First();//Comes as Argentina(Which is Fine)
string lasName = names.Last();//Comes Herzegovina
这就是我想要的方式
string Final = name + ". " + lasName;//Argentina + ". " + Bosnia and Herzegovina
有什么帮助吗??
【问题讨论】:
-
顺便说一句,这似乎是 SQL 注入攻击的可疑之处,因为您连接
msMatch.SelectedItem.Value而不是参数化matchId。 en.wikipedia.org/wiki/SQL_injection -
总是
"CountryA vs CountryB"吗? -
好吧,您可以使用正则表达式并查找“ vs. ”,但首先分别返回两个国家/地区名称不是更容易吗?
-
只有男生才能回答?
标签: c# asp.net string string-split