开发者

how to maintain the spaces between the characters?

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{ Buffe开发者_高级运维redReader 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


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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜