Java.lang.String:   How can we replace the list of characters in a String?

String s = "abc$d!efg:i";
s = s.replace('=', ' ');
s = s.replace(':', ' ');
s = s.replace('$', ' ');
s = s.replace('!', ' ');
I want to check a list of illegal characters(Ex: $ = : ! ) present in the String 's' and replace all the occurance with empty space ' '
I feel difficult to follow the above code style.. Because, If list of illegal characters increased, need to add the code again to check & replace the respective illegal character.
Can we refactor the above code with any other simple way?
Is there any other way to use Map/Set in this above example?

RTFM
http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html
That document is almost perfectly useless for someone
who is just starting to learn regexes. What they
need is a good tutorial, and the best one I know of
for Java programmers is the one at
this site. When you're ready to move on from
introductory tutorials, get the latest edition of
Mastering Regular Expressions, by Jeffrey Friedl.Dear Uncle,
maybe you want to read that document first before judging its usefulness. And just in case you can't be bothered, the following is an exact quote, which accidently happens to clearly explain the op's question on the usage of \\[\\] in sabre's regex:
Backslashes, escapes, and quoting
The backslash character ('\') serves to introduce escaped constructs, as defined in the table above, as well as to quote characters that otherwise would be interpreted as unescaped constructs. Thus the expression \\ matches a single backslash and \{ matches a left brace.
It is an error to use a backslash prior to any alphabetic character that does not denote an escaped construct; these are reserved for future extensions to the regular-expression language. A backslash may be used prior to a non-alphabetic character regardless of whether that character is part of an unescaped construct.
Backslashes within string literals in Java source code are interpreted as required by the Java Language Specification as either Unicode escapes or other character escapes. It is therefore necessary to double backslashes in string literals that represent regular expressions to protect them from interpretation by the Java bytecode compiler. The string literal "\b", for example, matches a single backspace character when interpreted as a regular expression, while "\\b" matches a word boundary. The string literal "\(hello\)" is illegal and leads to a compile-time error; in order to match the string (hello) the string literal "\\(hello\\)" must be used.

Similar Messages

  • How can I replace the cursor in the below query?

    I have this below query which calls a stored procedure that takes only 1 item's attributes at a time. But because of performance problems we are
    required to remove the cursor. How can I replace the below cursor logic with set operations or CTE? Please advice.
    DECLARE db_cursor_ava CURSOR
    FOR
    SELECT t.[agent-id],
    t.[start-date],
    t.[end-date],
    t.[monitor-days],
    t.[monitor-start],
    t.[monitor-end],
    t.[timezone-offset]
    FROM @tmpAgentPeriodTimeRange t
    OPEN db_cursor_ava
    FETCH NEXT FROM db_cursor_ava INTO @agentID_ava,
    @stDateTime_ava,
    @endDateTime_ava,
    @monDays_ava,
    @monSt_ava,
    @monEnd_ava,
    @offset_ava
    WHILE @@FETCH_STATUS = 0
    BEGIN
    DELETE
    FROM @tmpMonitorPeriod
    DELETE
    FROM @tmpFinalResult
    SET @runID = 1
    IF(@endDateTime_ava>DATEADD(MI,@offset_ava, GETUTCDATE()))
    BEGIN
    SET @endDateTime_ava=DATEADD(MI,@offset_ava, GETUTCDATE())
    END
    INSERT INTO @tmpMonitorPeriod
    EXEC core.usp_GetMonitoringPeriod
    @startDate = @stDateTime_ava,
    @endDate = @endDateTime_ava,
    @monitoringDays = @monDays_ava,
    @monitoringStart = @monSt_ava,
    @monitoringEnd = @monEnd_ava
    SELECT @maxID = MAX(tm.id)
    FROM @tmpMonitorPeriod tm
    FETCH NEXT FROM db_cursor_ava INTO @agentID_ava,
    @stDateTime_ava,
    @endDateTime_ava,
    @monDays_ava,
    @monSt_ava,
    @monEnd_ava,
    @offset_ava
    END
    CLOSE db_cursor_ava
    DEALLOCATE db_cursor_ava
    mayooran99

    You've been down this path before  - and the response is exactly the same.
    how to replace cursor logic
    And I'll suggest that you post the entire code - since you repeatedly delete 2 table variables but only populate one. The setting of @maxID also seems to have no purpose. And perhaps the issue here isn't the cursor but the general approach.  Who knows
    - but it appears you may have prematurely assumed that the cursor is the problem.

  • How can i replace the battery of an iPad 2?

    How can I replace the battery of an 3.5 year old IPAD 2?
    battery is empying fast compared to when I bought it and I would want to give this to my parents

    Apple will replace the battery for you. See here for details: https://www.apple.com/batteries/replacements.html

  • HT4060 how can i replace the battery on my ipad? it wont charge all the way

    my ipad will only charge to 14% then goes down...how can i replace the battery?

    iPad Owners
    Your one-year warranty includes replacement coverage for a defective battery. You can extend your coverage to two years from the date of your iPad purchase with the AppleCare Protection Plan for iPad. During the plan’s coverage period, Apple will replace the battery if it drops below 50% of its original capacity. If it is out of warranty, Apple offers a battery replacement for $99, plus $6.95 shipping, subject to local tax. Apple disposes of your battery in an environmentally friendly manner.
    http://www.apple.com/batteries/replacements.html

  • How can i replace the standard ESS iview with my own iview

    I want to replace standard ESS addr iview with my own WD developed by ABAP
    I added the iview(my WDA) into standard ESS addr page.
    (pcd:portal_content/com.sap.pct/every_user/com.sap.pct.erp.ess.bp_folder/com.sap.pct.erp.ess.pages/com.sap.pct.erp.ess.personal_information/com.sap.pct.erp.ess.cn/com.sap.pct.erp.ess.addr/com.sap.pct.erp.ess.addr)
    And make it visible.
    But I got this error in ESS PA addr :
    WebDynpro Exception: Application PER_ADDRESS_CN Does Not Exist
    Here is the error code :
    Error code:ICF-IE-http-c:100-u:AC_WANGFZ-l:1-s:CE1-i:SAPCE101_CE1_01-w:0-d:20070514-t:172301-v:RABAX_STATE-e:UNCAUGHT_EXCEPTION
    So , how can i replace the standard ESS iview with my own iview?
    Thanks

    Can you see any Javascript EPCF code in the old iView  ?  You are surely just going to have to find it  (if our hunch is correct) and analyse it and copy it into your new iView so that it functions in some way that at least does not error

  • How can I replace the old commenting system with Disqus?

    How can I replace the old commenting system on Business Catalyst with Disqus? Please help

    Hi,
    The Disqus integration has been done by at least one BC partner – simpleflame.com, on this site: http://kiyuco.com/free-videos . You could reach out to them inquiring for more details on how it has been done.
    Kind regards,
    -Sidney

  • How can I replace the SIM on Droid Ultra?

    How can I replace the SIM on Droid Ultra?

    SIM cards are free at your local Corporate Verizon store.
    SIM Card - Inserting/Removing - DROID Mini / DROID Ultra / DROID Maxx by Motorola

  • How can I replace the out of the box photos with my own when music is playing?

    How can I replace the out of the box photos with my own when music is playing?

    Welcome to the Apple Community.
    Select any photos you want to share with the Apple TV using the iTunes advanced menu (using iPhoto is the better option but a folder will work). Once all the photos you want are shared, go to settings > screensaver on the Apple TV and choose which of those shared photos you want to use with your screensaver.

  • How can I replace the current contacts list and put in my own

    How can I replace the current contacts list and put in my own?  My son's name and contact list appear, inadvertently loaded when he used the iPad.  I have an iPad mini, fully updated to iOS 7.0.4.

    He must have signed into his icloud account using your device.  You need to disconnect the device from that account and then sign in using your account ID.
    Go to Settings>icloud, scroll to bottom of screen and tap Delete Account.  Then log in using a different ID.

  • Since I am writing the book in Italian,how can I replace the word CHAPTER with CAPITOLO ?

    Since I am writing the book in Italian, how can I replace the word CHAPTER with CAPITOLO ?

    I think you need to run iBA in Italian so the templates are in that language.  You can do that by switching your OS X to Italian and then reopening iBA or perhaps by using this app to just change the iBA language:
    http://www.tj-hd.co.uk/en-gb/languageswitcher/
    see also
    https://discussions.apple.com/message/20745332#20745332

  • How can i get the list of all users present in the LDAP

    Hi Experts,
    How can i get the list of all users present in the LDAP ?
    Is there any API or function Code to get all user list??
    Please help me out!!!
    Help will be rewarded

    Well it will depend on exactly where your UME configuration points to in the LDAP tree but yes, it is possible to get all users.  Something like the following should do it:
    import com.sap.security.api.*;
    import com.sapportals.portal.prt.component.*;
    IUserFactory iuf;
    ISearchResult isr;
    IUser user
    String userid;
    iuf = UMFactory.getUserFactory();
    isr = iuf.getUniqueIDs();
    you will need to iterate the ISearchResult object but you can get IUser objects by
    userid = (String)isr.next();
    user = iuf.getUser(userid);
    then you can imanipulate / identify / or whatever you need with the user object
    Haydn

  • How can i get the list of all users present in the UME ?

    Hi Experts,
    How can i get the list of all users present in the UME ?
    Is there any API or function Code to get all user list??
    Please help me out!!!
    Help will be rewarded
    -pankaj chouhan

    Hi Pankaj,
    find the official NetWeaver security javadocs (including access to UME) <a href="http://help.sap.com/javadocs/NW04S/current/se/index.html">here</a>. Look for classs UMFactory and proceed from there.
    Best regards,
    Martin

  • How can we display the list of Report Names in Dashboard Prompt?

    How can we display the list of Report Names in Dashboard Prompt?

    Hi,
    No its not possible to display list of reports in dashboard prompts.
    Can do this using SQl results in prompt(we write query checking out report names manualy),but its not easy thing if you are having many report names to be displayed.
    Assign points and close your threads if answered.
    Refer : http://forums.oracle.com/forums/ann.jspa?annID=939
    Regards,
    Srikanth

  • How can I control the list of cipher suites offered in the SSL Client Hello message? I want to forbid MD5 and RC4.

    How can I control the list of cipher suites offered in the SSL Client Hello message?
    I want to limit my browser to negotiating strong cipher suites. I'd like to forbid DES, MD5 and RC4.

    Set the related SSL3 prefs to false on the about:config page (Filter: security.ssl3.).
    *http://kb.mozillazine.org/about:config

  • How can i get the list of DB02's Table spaces-overview?

    Dear Experts,
           Could you help me about how can i get the list of DB02's Table spaces-overview? which function module can do it?
    Thanks a lot

    Hi,
    Execute this FM DB02_ORA_FILL_TD110
    U will get all the details of table spaces in the importing parameter TD110 of that FM.
    Reward if helpful
    Regards
    Vodka.

Maybe you are looking for

  • Dreamweaver Rollover Help

    When making a webpage, rollover images malfunction to show the rollover change over one central image, instead of the specified image. What did I do wrong? Here's what I mean (ignore the whote squares, I edited out the title and any telling informati

  • I can't update from 1.1.5 to 2.0.1

    I just got my iPod touch yesterday, but whenever I try to update to 2.0.1, it gets stuck when it tries to prepare my ipod for restore. I get the error 1604, and I have the latest itunes and everything. Each time I try to update it I can't restore my

  • Can't start J2EE server

    I have installed Java 2 SDK, Enterprise Edition version 1.3 on Win NT server. Installation was successfull. While starting J2EE server, I am getting following error: Exception in thread "main" java.lang.NoClassDefFoundError: COMPUTER\db\

  • I have a -69 error, and my iPod is practically broken. HELP!

    I have a list of problems: -Only my left speaker works no matter what headphones I put in my iPod. -I get an error (-69) when I try to update my iPod. The so called "corrupted file" is different every time. -Half the songs on my iPod stop half-way an

  • Deleteing parameter name & value

    Hi, Kindly let me know the procedure to delete parameter name & and value from database profile eg. log_checkpoint_timeout. I'm on ECC 5.00 with oracle 9i and linux platform. Thanks & Regards, Atul K