Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Working with strings: Java

  • 18-01-2007 12:29AM
    #1
    Registered Users, Registered Users 2 Posts: 279 ✭✭


    Hey guys, just thought there'd be some Java gurus in here who can help me with this problem.
    I have a string and I am replacing every space with a '+' but does anyone know how I can detect a carriage return and line feed (CRLF) within the string so I can replace this with a '+' much like the spaces?
    Here's the code I'm using to replace every space with a +.

    for (int x=0; outgoingSmsMsg.length(); x++ {
    if (outgoingSmsMsg.charAt(x) == ' ' {
    outgoingSmsMsg = outgoingSmsMsg.replace(' ', '+');
    }
    }

    Regards,
    Digi.


Comments

  • Closed Accounts Posts: 362 ✭✭information


    if(outgoingSmsMsg.contains("\n"))
        outgoingSmsMsg = outgoingSmsMsg.replace('\n','+');
    if(outgoingSmsMsg.contains(" "))
        outgoingSmsMsg = outgoingSmsMsg.replace(' ','+');
    if(outgoingSmsMsg.contains("\r"))
        outgoingSmsMsg = outgoingSmsMsg.replace('\r','+');
    


Advertisement