tags:

views:

42

answers:

2

hi

i am using the following code

String keyword=request.getParameter("keyword");
keyword = keyword.toLowerCase(); keyword.replaceAll(" "," "); //first double space and then single space keyword = keyword.trim();
System.out.println(keyword); i am given the input as t s but iam getting as [3/12/10 12:07:10:431 IST] 0000002c SystemOut O t s // here i am getting the two spaces how can decrease two single space

use the follwoing program

public class whitespaces { public static void main(String []args){ try{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = br.readLine(); System.out.println( str.replaceAll("\b\s{2,}\b", " ")); }catch(Exception e){ e.printStackTrace(); } } }

thanks,

murali

A: 

StackOverflow has solved the same (or at least a similar) problem regarding spaces in tags, by not having them. Instead, if you want to denote a space in a tag on SO, use - (dash). You could run a query to replace all spaces with - in your database (even though it would probably take quite some time to run you'll only have to do it once). If you want to display them as spaces on the page, just do a replace when you render.

Tomas Lycken
+1  A: 

If your database always have only one space, you could use some keypress event to automatically ignore any occurrences of multiple spaces (by replace double spaces with single space in the search string or something).

awe
can you provide any java program for this.....
murali
hi i am using the following code String keyword=request.getParameter("keyword"); keyword = keyword.toLowerCase(); keyword.replaceAll(" "," "); keyword = keyword.trim(); System.out.println(keyword);i am given t s then it print as [3/12/10 12:07:10:431 IST] 0000002c SystemOut O t show can do for print like t s(single space)thanks,Murali
murali