|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
check for extra spaces
how do i check if a string contains extra spaces. eg:"try erte"
in the above string, it contains more than 1 space, how do i remove the extra spaces?? codes would be helpful. thanks... pls help asap.... |
|
#2
|
|||
|
|||
|
peter, can you upgrade to jdk 1.4? All this text searching stuff that you're doing would be dirt simple with the regex functions.
|
|
#3
|
|||
|
|||
|
Turns out this was really easy.
Code:
<%@page contentType="text/html"
%><%@page import="java.util.StringTokenizer"
%><html>
<head><title>JSP Page</title></head>
<body>
<%
String testString = " This is a test string to print out ";
String newString = "";
StringTokenizer st = new StringTokenizer( testString);
while (st.hasMoreTokens()) {
newString += st.nextToken();
newString += " ";
}
newString = newString.trim();
%>
<p>The new string is:</p>
<p><%= newString %></p>
</body>
</html>
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > check for extra spaces |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|