问题
For Example:
String str="A:B";
I want to split A & B using Struts2 tags and display individually.
回答1:
Like @Alexander Cogneau says or with String::split function
here is an example:
java
public String[] getSplittedString() {
String str = "A:B";
return str.split(":");
}
interface
<s:iterator value="splittedString" status="someSplittedString" var="string">
<s:textfield name="splittedString" value="%{#string}"></s:textfield>
</s:iterator>
回答2:
You can use the String.indexOf() method to get the ":" and then use String.substring() to split the string at certain indexes. So in your case that would be something like this:
String str="A:B";
int position = str.indexOf(':');
String beginning = str.substring(0, position-1);
String end = str.substring(position);
来源:https://stackoverflow.com/questions/19996543/how-to-split-a-string-using-struts-2-tags