×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Jan 2008
    Location
    mysore
    Posts
    52

    need to trim the all white spaces in astring

    hi
    how to trim all the entire string to remove the white spaces
    is it possible ,i sawed so many examples every one answer just trim .that is reduces the space of before starting character spacess only reducess ,remianing spaces is not effected .

    Eg: hello how are you?

    i want to : hello how are you?

    it is possible ?

    regards,
    tallapaneni.

  2. #2
    Regular Contributor
    Join Date
    Jan 2008
    Location
    mysore
    Posts
    52

    Re: need to trim the all white spaces in astring

    hi
    the below message is i gave spaces

    but it trims here
    my problem is

    Eg: --------how---------are-- you?
    (FOR KIND INFORMATION -- is takes spaces) thanyou


    answer: how are you?

    regards,
    tallapaneni

  3. #3
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: need to trim the all white spaces in astring

    I don't know if I've clearly understood your problem, but if you want to normalize multiple whitespaces, replacing them with a single whitespace, you can try this code snippet:

    Code:
    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();
    }
    Pit

  4. #4
    Regular Contributor
    Join Date
    Jan 2008
    Location
    mysore
    Posts
    52

    Re: need to trim the all white spaces in astring

    Quote Originally Posted by jappit View Post
    I don't know if I've clearly understood your problem, but if you want to normalize multiple whitespaces, replacing them with a single whitespace, you can try this code snippet:

    Code:
    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();
    }
    Pit


    hi thankyou
    that one is 100% working , thanq thanks a lot.

    Regards,
    tallapaneni.

  5. #5
    Regular Contributor
    Join Date
    Jan 2008
    Location
    mysore
    Posts
    52

    another dought at error

    hi this is another dought ------------------------------
    No line matching interface Clip supporting format PCM_SIGNED 11025.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian is supported.

    i used an alert function it comes , I don't know exactly why it occurs it displays only one time.next time it not occur i observerd in output box.

    Regards,
    Tallapaneni.

Similar Threads

  1. CParser - white spaces?
    By b0ssY in forum Symbian
    Replies: 5
    Last Post: 2007-07-03, 07:44
  2. White screen problem
    By Tesctassa in forum Mobile Java General
    Replies: 5
    Last Post: 2007-02-01, 11:05
  3. DriverException: Problems with JAXP: White spaces are required between publicId and s
    By ileoo in forum Digital Rights Management & Content Downloading
    Replies: 0
    Last Post: 2004-02-04, 10:01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×