我有一個java問題。我無法弄清楚如何編寫正則表達式來在遇到一個或多個'#'實例時將某些內容打印到文件中。當string equals
「」不能打印時,但必須打印string equals
「#」。這裏是我的代碼:正則表達式識別'#'字符串
int num = 1;
StringBuffer noletterbuf = new StringBuffer(nospaces);
noletterbuf.deleteCharAt(0);
String noletter = noletterbuf.toString();
//if(num == noletter.split("[^#]").length){//applies # to C# and C
if(num == noletter.split("[#*]").length){//applies # to C
double yacc = octave*-50;
p6.println("sb.append(\"/Times-Roman findfont 70 scalefont setfont 1 -1 scale newpath \"); sb.append(" + xaccplace + " + \" \" +" + yacc + " + \" moveto \"); sb.append(\"(#) show 1 -1 scale \");");
}
在此先感謝! Bjorn
或noletter.contains(「#」) – 2013-03-03 17:50:06
@CyrilleKarmann Yup。但對於單字符檢查,我總是使用'indexOf()',因爲我相信它更快。 – Eric 2013-03-03 17:51:13
謝謝。有用。 – user1189952 2013-03-03 17:51:25