如果截取SQL语句Where前面的所有字符串
如select * from a  -->  select * from a
select a.id,name from a where id='aa' --> select a.id,name from a

解决方案 »

  1.   

    string TestString = "select a.id,name from a where id='aa' ";
    TestString.Substring(0,TestString.IndexOf("where"))
      

  2.   

    楼上的代码我试过,第一种情况找不到所以无法通过。我觉得应该写一个函数func(string select,string from)select和from分别是两处关键字里面的东西,随后得出这两个东西的长度,再加上select 和 from 还有 空格 的长度,最后取出前面的substring(0,长度)这样应该就不会报错了
      

  3.   

    第一种情况找不到所以无法通过?什么意思啊?
    如果是担心没有where
    你可以加判断阿!
    if(TestString.IndexOf("where")<0)
       return TestString;