java解析字符串(解析sql语句,得到需要查询显示的字段名)。

JavaScript028

java解析字符串(解析sql语句,得到需要查询显示的字段名)。,第1张

我写一条把

String aa=''select "+f_spbm+" from 表1"

主要注意其中的空格 select 后面的, from前面的空格。。

第二条一样。。表不固定,字段也就不能固定,功能也就不能固定,一般编写都会将表固定的。

资料:网页链接

javascript中判断字符串是否以指定字符串开始或结尾:

//判断当前字符串是否以str开始 先判断是否存在function是避免和js原生方法冲突,自定义方法的效率不如原生的高

if (typeof String.prototype.startsWith != 'function') {

   String.prototype.startsWith = function (str){         

      return this.slice(0, str.length) == str

   }

}

//判断当前字符串是否以str结束

if (typeof String.prototype.endsWith != 'function') {

 String.prototype.endsWith = function (str){          

  return this.slice(-str.length) == str

 }

}    

     

//测试程序

var sCompareStr = "select * from t1"//比较字符串

var sBeCompareStr = ""//被比较字符串

if(sCompareStr.endsWith(sBeCompareStr)){//这里可以替换为startsWith

    alert(sCompareStr+" 是以:"+sBeCompareStr+" 结束")

}else{

    alert(sCompareStr+" 不是以:"+sBeCompareStr+" 结束")

    sCompareStr +=sBeCompareStr //若无分号,将分号加到后面

}

这样书写的原因:

之所以在将整个代码放在if判断中是因为避免以后原生的js版本中增加了同类方法而导致代码效率降低。因为对于同名方法来说,js原生的代码效率要高于用户自己扩展的方法

之所以使用slice方法而不使用indexof方法,是由于indexof方法在处理较长的字符串时效率比较低

这个可以搬过去用,楼主若觉得回答有所帮助,望采纳,谢谢!