This page was last modified 14:55, 6 May 2008.
Normalize string whitespaces with J2ME
From Forum Nokia Wiki
A simple method to normalize String multiple whitespaces (replacing them with a single whitespace). For example, to normalize the String:
" Normalize all whitespaces "
to:
" Normalize all whitespaces ".
String normalizeWhitespaces(String s) { StringBuffer res = new StringBuffer(); int prevIndex = 0; int currIndex = -1; int stringLength = s.length(); String searchString = " "; while((currIndex = s.indexOf(searchString, currIndex + 1)) >= 0) { res.append(s.substring(prevIndex, currIndex + 1)); while(currIndex < stringLength && s.charAt(currIndex) == ' ') { currIndex++; } prevIndex = currIndex; } res.append(s.substring(prevIndex)); return res.toString(); }
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 如何在定时重定向中提交变量参数值的?? | ratengit | Web Technologies and Multimedia Content- Web 技术和多媒体内容 | 0 | 2004-06-14 18:21 |
| 6230显示中文是不是有点问题? | lawrence1980 | Other Programming Discussion 关于其他编程技术的讨论 | 4 | 2004-08-14 08:56 |
| CAknTextQueryDialog - How to accept empty string? | relliott98 | Symbian User Interface | 5 | 2006-08-01 16:19 |
| How to concatenate HBufC's text? | Sneha1 | Symbian User Interface | 7 | 2007-09-26 10:10 |
| How to set different icons in ListBox? | daip02 | Symbian User Interface | 4 | 2004-07-05 11:17 |
