仅打印字符串的特定部分
Print only a specific part of a string
我有一个 jsp 程序(使用 scriplet)生成字符串中的输出。
我的JSP代码:
<HTML>
-------
-------
<%
-------
-------
a=new String(tmp, 0, i);
out.println(a);
-------
-------
%>
-------
</HTML>
到这里我已经成功获取输出了。但是我得到了很多不必要的数据。我的 jsp 显示如下输出:
值:XXXXXX 位置:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX....
我只想打印字符串的值部分。我想省略从 "Location: XXXXXXXXX" 开始的所有内容。它总是给我这种格式的输出。
有什么办法吗?
如有任何帮助,我们将不胜感激。提前致谢。
我相信您是在问如何获取字符串的一部分;这真的与 JSP.
没有任何关系
要仅获取 "Location:" 之前的字符串的第一部分,您需要使用子字符串方法:
out.println(a.substring(0, a.indexOf("Location:"));
这表示,'give me a part of the string starting at 0 (the first character) up to (but not including) the first index of "Location:" in the string'。
我有一个 jsp 程序(使用 scriplet)生成字符串中的输出。
我的JSP代码:
<HTML>
-------
-------
<%
-------
-------
a=new String(tmp, 0, i);
out.println(a);
-------
-------
%>
-------
</HTML>
到这里我已经成功获取输出了。但是我得到了很多不必要的数据。我的 jsp 显示如下输出:
值:XXXXXX 位置:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX....
我只想打印字符串的值部分。我想省略从 "Location: XXXXXXXXX" 开始的所有内容。它总是给我这种格式的输出。
有什么办法吗?
如有任何帮助,我们将不胜感激。提前致谢。
我相信您是在问如何获取字符串的一部分;这真的与 JSP.
没有任何关系要仅获取 "Location:" 之前的字符串的第一部分,您需要使用子字符串方法:
out.println(a.substring(0, a.indexOf("Location:"));
这表示,'give me a part of the string starting at 0 (the first character) up to (but not including) the first index of "Location:" in the string'。