开发者

Trim function not removing spaces in name

bool Res = false;  

DataView DV = new DataView(DT);
     DV.RowFilter = "Trim(Originator)='"+OrginatorName.Trim()+"'";
     if (DV.Count > 0)
     {
       Res = true;
     }
开发者_开发知识库

I need to get "Originator" from the database and compare it with the OrginatorName to check duplicate values. I need to remove all the white spaces before checking.

For example, the function must consider "John Van" to be the same as "JohnVan". My above code doesn't work. How can I achieve this?


String.Trim() removes whitespace from the beginning and end only, not in the middle. You want to use the String.Replace() method

DV.RowFilter = "Trim(Originator)='"+OrginatorName.Replace(" ", "")+"'";


this line should be

  DV.RowFilter = "Trim(Originator)='"+OrginatorName.Replace(" ","")+"'";


User .Replace instead of .Trim()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜