English 中文(简体)
Java Regex to see if a String includes %, %d, %n
原标题:Java Regex to see if a String contains %s, %d, %n

<<><><>>>> 我写一下我自己对<代码>至String()方法的改动,基本上,当你把你通过的方法称作“扼杀”,然后是“条码”(目标......动力)

this.toString("%8s", this.log, "%n%s %s", this.theMap, "%s", this.countIterator());

从那以后,我使用以下法典来判断,提出的论点是否是一种固定的尝试或形式。

if(args[i].getClass().getName() == "java.lang.String") {
  if(args[i].toString().contains("%\-?[1-9]s?*")) {

    format = args[i].toString();

  } else {

    s += args[i].toString();

  }
}

The args[i].toString().contains("%\-?[1-9]s?*") regex isn t working, however when I use args[i].toString().matches("%\-?[1-9]s?*") it works but only for instances of a String with %s or %9s not for instances with %s %9s or %s%s %s. And it also works when I swap the s in the regex with a d or n.

我知道你问,为什么要重新发明轮椅,只是使用<代码>String.format(),如果我只想这样做,我就能够做任何事情,直到我解决。

I also tried copying and pasting the java.util.Formatter class
"%(\d+\$)?([-#+ 0,(\<]*)?(\d+)?(\.\d+)?([tT])?([a-zA-Z%])" regex but it did the same as above and only worked for %s or %9s.

我还在格式班中注意到,开发商利用了“彩虹”类的事例,并使用了“缝.”类,通过“缝.”进行操作,对模式的每一种情况进行对比,并储存到“阿雷拉”号。 我并不真的希望这样做,我只想看到,Sting论点有一个例子:%n%s%d,并从中将其储存在后面与String.format(format, debate);

So if anyone could help me that would be awesome!
Thank you for reading this far.

最佳回答

引言

Pattern p = Pattern.compile("(%[0-9]*(s|d|n))");
System.out.println("match: " + p.matcher(str).find());

您可以储存这一模式,作为全球或静态变量,并在需要时重新使用。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签