How to split a string using struts 2 tags? [duplicate]

陌路散爱 提交于 2019-12-24 22:42:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!