Results 1 to 7 of 7
  1. #1
    JordashTalon is offline Member
    Join Date
    Jan 2009
    Posts
    37
    Rep Power
    0

    Default Have a period in string, how to make it look nicer

    I have a period in a string like this:

    "This is a cool string . ";

    I want to make every period in the string
    be like this:

    "This is a cool string. ";

    Any ideas on how to do that?

    Thanks

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You may need to provide more context here. Otherwise we may not be able to tell you much other than to not place your periods in the wrong location.

    By context: how are you getting your strings? File? user input? hard coded in the program? What are you doing with the strings once you have them? What's the ultimate goal of this program / assignment?
    Last edited by Fubarable; 03-04-2009 at 02:06 AM.

  3. #3
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    string . ";
    it looks like a package name :) what you mean saying period. Give us more information

  4. #4
    JordashTalon is offline Member
    Join Date
    Jan 2009
    Posts
    37
    Rep Power
    0

    Default

    Sorry it's a string being pulled in from a text file, the text file is intentionally horrendous, e.g. extra whitespaces etc.. So basically i've been able to strip everything down to just a single space between characters, the problem is some of the periods in the string have an extra space and I'm trying to think of a regular expression or something that will trim out all leading spaces of a period (.), hope that makes sense.

  5. #5
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    this forum stripped away the extra spaces.
    i think this is what the op is asking.
    Java Code:
    "This is a cool string        .      "; // error
    "This is a cool string."; // desired result.
    edit:
    and i'd say use s.replaceAll("\\s*\\.",".");
    hadn't tested the regex out yet.
    Last edited by angryboy; 03-04-2009 at 03:43 AM.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I'm not clear too what our thread started looking here. May be he wants to remove the space just before the full-stop mark.

  7. #7
    JordashTalon is offline Member
    Join Date
    Jan 2009
    Posts
    37
    Rep Power
    0

Similar Threads

  1. simplest way to make 2d array to string
    By Tamu in forum Advanced Java
    Replies: 4
    Last Post: 11-25-2008, 05:50 PM
  2. How to make Java see a string as html
    By matpj in forum Java Applets
    Replies: 4
    Last Post: 09-26-2008, 04:40 AM
  3. how do i make a string return a number?
    By pjr5043 in forum New To Java
    Replies: 6
    Last Post: 09-15-2008, 05:56 AM
  4. signing applets for a period of time
    By sandeepk84@gmail.com in forum Java Applets
    Replies: 0
    Last Post: 12-04-2007, 02:34 PM
  5. make a variable name from a string?
    By Kinnikinnick in forum New To Java
    Replies: 3
    Last Post: 11-13-2007, 04:54 PM

Posting Permissions

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