Deletion of Characters in String

Hi I having a problem. Below shows
String s = "Hello";
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != 'e' && s.charAt(i) != 'o') {
System.out.print(s.charAt(i));
If I want to let user to key in the string and the program will be able to delete the 'e' and the 'o'. How do I do that?

If I want to let user to key in the string Look at the Scanner class to see how you can
get user-input (through the console):
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scan
ner.html
and the program will be able to delete the 'e' andthe 'o'.
How do I do that?Look at String's replace(...) method:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Stri
ng.htmlPossible to type it out? Or complete the coding? Cos dont quite get it.
Thanks.

Similar Messages

  • Deleting extra characters

    Is there a way to delete extra characters in a StringBuffer after the first occurance? For example, if I wanted to delete all comma's after the first occurance in a string, this seems to work:
              if(custName.lastIndexOf(",") > custName.indexOf(","))
                   custName.replace(' ,' , ' ');
    But how would you do this in a StringBuffer? I have tried using something like this:
    int numComma = 0;
    for(int i = 0; i < letter.length(); i++)
    if(letter.charAt(begin) == ',')
         numComma ++;
    if( letter.charAt(begin) == ',' && numComma > 1)
         letter = letter.deleteCharAt(begin);
    but it deletes all commas, including the first occurrance..Would you use the same approach to delete extra spaces between words?[if there is more than one space] Any suggestions would be appreciated..

    if you use java.util.stringtokenizer you can tokenize by your delimiter.

  • My backspace key delete two characters in Firefox.

    My backspace key delete two characters in Firefox. How may I solve this problem?
    It works in other programs such as Office well. My OS is WIN7.
    Please help me.

    Application Basics
    Name: Firefox
    Version: 29.0
    User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0
    Crash Reports for the Last 3 Days
    All Crash Reports (including 1 pending crash in the given time range)
    Extensions
    Name: Adblock Plus
    Version: 2.6
    Enabled: true
    ID: {d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}
    Name: IDM CC
    Version: 7.3.73
    Enabled: true
    ID: [email protected]
    Name: Right Inbox
    Version: 1.0
    Enabled: true
    ID: {eb692b9a-0dce-45fa-b0e6-765d83e386bd}
    Name: Adobe Acrobat - Create PDF
    Version: 1.0
    Enabled: false
    ID: [email protected]
    Name: PDF Architect Converter For Firefox
    Version: 1.0
    Enabled: false
    ID: [email protected]
    Important Modified Preferences
    browser.cache.disk.capacity: 358400
    browser.cache.disk.smart_size_cached_value: 358400
    browser.cache.disk.smart_size.first_run: false
    browser.cache.disk.smart_size.use_old_max: false
    browser.places.smartBookmarksVersion: 6
    browser.sessionstore.upgradeBackup.latestBuildID: 20140421221237
    browser.startup.homepage: www.google.com
    browser.startup.homepage_override.buildID: 20140421221237
    browser.startup.homepage_override.mstone: 29.0
    dom.mozApps.used: true
    extensions.lastAppVersion: 29.0
    network.cookie.prefsMigrated: true
    places.database.lastMaintenance: 1399615634
    places.history.expiration.transient_current_max_pages: 104858
    plugin.disable_full_page_plugin_for_types: application/pdf
    plugin.importedState: true
    privacy.sanitize.migrateFx3Prefs: true
    storage.vacuum.last.index: 0
    storage.vacuum.last.places.sqlite: 1399534769
    Graphics
    Adapter Description: ATI Mobility Radeon HD 5470
    Adapter Drivers: atiu9p64 aticfx64 aticfx64 atiu9pag aticfx32 aticfx32 atiumd64 atidxx64 atidxx64 atiumdag atidxx32 atidxx32 atiumdva atiumd6a atitmm64
    Adapter RAM: 1024
    ClearType Parameters: Gamma: 2200 Pixel Structure: R ClearType Level: 100 Enhanced Contrast: 300
    Device ID: 0x68e0
    Direct2D Enabled: Blocked for your graphics driver version. Try updating your graphics driver to version 10.6 or newer.
    DirectWrite Enabled: false (6.1.7600.16385)
    Driver Date: 1-22-2010
    Driver Version: 8.692.1.0
    GPU #2 Active: false
    GPU Accelerated Windows: 1/1 Direct3D 9
    Vendor ID: 0x1002
    WebGL Renderer: Google Inc. -- ANGLE (ATI Mobility Radeon HD 5470 Direct3D9Ex vs_3_0 ps_3_0)
    windowLayerManagerRemote: false
    AzureCanvasBackend: skia
    AzureContentBackend: cairo
    AzureFallbackCanvasBackend: cairo
    AzureSkiaAccelerated: 0
    JavaScript
    Incremental GC: true
    Accessibility
    Activated: false
    Prevent Accessibility: 0
    Library Versions
    NSPR
    Expected minimum version: 4.10.3
    Version in use: 4.10.3
    NSS
    Expected minimum version: 3.16 Basic ECC
    Version in use: 3.16 Basic ECC
    NSSSMIME
    Expected minimum version: 3.16 Basic ECC
    Version in use: 3.16 Basic ECC
    NSSSSL
    Expected minimum version: 3.16 Basic ECC
    Version in use: 3.16 Basic ECC
    NSSUTIL
    Expected minimum version: 3.16
    Version in use: 3.16

  • Characters in String : Unicode 16-bit to custom 32-bit

    I understand that internally in Java, characters in Strings are actually Unicode characters, with each character represented with 16 bits.
    So, character �L� in Unicode is 0x004C
    which is also 0000 0000 0100 1100
    Now, I wish to encode each of the 4 bits above into individual ASCII characters:
    = 0 0 4 C
    = 0x30 0x30 0x34 0x43
    = 00110000 00110000 00110100 01000011
    So, from the original 16-bit character in Java, I want a final 32-bit.
    Eventually, I�ll need to send the final result over the network, via OutputStream/writer and socket.
    Can someone help me on this ? Or give me some ideas... Thanks.

    trick: prepend the number with 1 and use substring... like int charWith1 = c + 0x10000. That'll make charWith1 to be of the format 0x1XXXX. Then call hexstring on that, you get a string like "1XXXX." Then you can drop the 1 with a call to substring.
    of course there are methods that use only bit operations and additions to do it, making it a bit faster.. like this:
    byte byte0 = (byte) ((c & 0x000F) + '0');
    byte byte1 = (byte) (((c & 0x00F0) >> 4) + '0');
    ...

  • Removing non-numeric characters from string

    Hi there,
    I need to have the ability to remove non-numeric characters from a string and I do not know how to do this.
    Does any one know a way?
    Example:
    Present String: (02)-2345-4607
    Required String: 0223454607
    Thanks in advance

    Dear NickM
    Try this this will work...........
    create or replace function char2num(mstring in varchar2) return integer
    is
    -- Function to remove Special characters and alphebets from phone no. string field
    -- Author - Valid Bharde.(India-Mumbai)
    -- Date :- 20 Sept 2006.
    -- This Function will return numeric representation.
    -- The Folowing program is gifted to NickM with respect to his post on oracle site regarding Removing non-numeric characters from string on the said date
    mstatus number :=0;
    mnum number:=0;
    mrefstring varchar2(50);
    begin
    mnum := length(mstring);
    for x in 1..mnum loop
    if (ASCII(substr(upper(mstring),x,1)) >= 48 and ASCII(substr(upper(mstring),x,1)) <= 57) then
    mrefstring := mrefstring || substr(mstring,x,1);
    end if;
    end loop;
    return mrefstring;
    end;
    copy the above program and use it at function for example
    SQL> select char2num('(022)-453452781') from dual;
    CHAR2NUM('(022)-453452781')
    22453452781
    Chao!!!

  • Deleting forwarding characters in an e-mail when menu feature has no effect

    Friends:
    How do I delete forwarding characters in an e-mail when option-commend-' doesn't have any effect? Yes, I'm actually in an editable window.
    Using latest version of Apple Mail on OS X 10.5.8
    Thanks,
    Migs

    Extensions
    Produtools Manuals 2.1 Community Toolbar 3.21.0.1 ({b2bf7b3f-bf0b-4c48-aec6-f92c51be63e1})
    Open the Add-ons Manager by
    Pressing the '''Alt''' or '''F10''' key to bring up the tool bar.
    Followed by; '''Tools > Add-ons.'''
    Hot key; '''<Control> ''(Mac: <Command>)'' <Shift> A)'''
    On the left side of the page, select Extensions.

  • Number of repeated characters in string array

    Hi,
    I m trying to get number of repeated characters in string array. I couldnt figure out where am i doing mistake.
    thank you,
    For example: count({"alpha, beta,"}, 'a')
    a is repeated 3
    l is repeated 1 etc.
    public class Test
    public static int count(String[] stringArray, char c)
    public String [] str = new String [2];
    int count = 0;
    str[0]
    str[1]
    for(int i = 0; i<str.length(); i++)
    if (str.charAt(i)
    count++;
    return count;

    There is a difference between a String and a String [].
    A String [] is an array of String class objects:/*  Traverse_Array_Of_Strings_1.java */
    public class Traverse_Array_Of_Strings_1
      public static void main(String [] argv)
        /* here is an array of Strings */
        String [] s = { "hello", "how", "are", "you" };
        int i, j;
        System.out.println("s.length = "+ s.length );
        for (i= 0; i < s.length; i++)
          System.out.println("s= <"+ s[i] +">");
          for (j= 0; j < s.length(); j++)
    System.out.print(s[i].charAt(j) +", ");
    System.out.println("\n-----");
    }output:java> javac Traverse_Array_Of_Strings_1.java
    java> java Traverse_Array_Of_Strings_1
    s.length = 4
    s= <hello>
    h, e, l, l, o,
    s= <how>
    h, o, w,
    s= <are>
    a, r, e,
    s= <you>
    y, o, u,
    Edited by: vim_no1 on Jul 15, 2010 7:43 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Delete a char from string ?

    Hi,
    I want to delete a char from string. i used the following function.
    String f = formulla.replace('[','');
    The above function doesnt work as it tells me to put a space or some char in 2nd parameter which i dont want. i just want to delete all occurences of some specific char in a string.
    Any suggestion.
    Thanks alot.

    u can do:
    String before;
    char charToReplace;
    StringBuffer tempBuf = new StringBuffer(before);
    for (int i=0; i<tempBuf.length(); i++)
            if (tempBuf.charAt(i)==charToReplace)
                  tempBuf.deleteCharAt(i);
    String after = tempBuf .toString(); HTH
    Yonatan

  • Replace special characters in String

    Dear Guru ,
    Does SAP provide the standard function that can replace the special characters in String ?
    For example :
    I have one template string : " & & & & & output(s) have not been processed yet ! " and five parameters : "P1" , "P2" , "P3" , "P4" , "P5" .
    And i would like to apply all parameters into the string to replace the "&" character . Is it possibile ?
    My idea is sourcing from the Message String that in tcode : SE91 .
    Thanks .
    Best Regards,
    Carlos Zhang

    Hi Carlos,
    I think instead of a standard FM you can write a one line command to do this job.
    E.g. 
    constant: str1 type string value 'output(s) have not been processed yet ! '.
    data: var1 type c,
             var2 type c,
             var3 type c,
             var4 type c,
             str    type string.
    concatenate var1 var2 var3 var4 str1 into str separated by space.
    So str will have the final value.
    Thanks,
    Mainak

  • How could I delete files with name string with "TAL" and older than 05.05.

    How could I delete files with name string with "TAL" and older than 05.05.2009 on unix

    Our ECC Ides system today was not responsible. For first time 17 users were working on the systtem (IWN2008/SQL2005 based). Before the people were maximally 5.
    The server is done by making a homogeneous system copy from an blade machine(now it is an VIrTUAL)
    There was enaught disk space. However I checked Wokload 03sdn transaction) inn system. and found out that at that time of restarting(I had to restart system 3 times to get logged on the system and even then it was almost unresponsive.
    I can found in there top abap."Login_Pw", "SESSION_MANAGER", "?". (BAtch), "ADMSBUF, >DEleyed Function call, RSPOWPOO""RSWWclear", ""VA01", "SAPMHHTP  "Buf  Sync" >DDLOC CLEANUP)""rsbtctE"
    What can I do?
    ¸
    Who could interfer SAP_CCMS_MONI_BATCH_DPSAP_CCMS_MONI_BATCH_DP
    the 2 main users under users profile were ZUGTIN running and SAPSYS( running many system jobs)
    How to approach the problem

  • I have an iPhone5. I update to iOS7. Now I cannot edit my messages. I have to delete the whole message string like in iPhone 1. What has gone wrong

    I have an iPhone5. I updated to iOS7. Now I cannot edit my messages. I have to delete the whole message string like in iPhone 1. What has gone wrong?

    Thanks it resloved my question, but Apple has made it more complicated it was so much easier to just press the edit button and select messages to be deleted. Now its cumbersome to delete several messages. Apple should give us back the edit button.

  • While I delete characters in firefox, it deletes two characters

    Hello there! I have been using Mozilla Firefox for a long time. Now I have problems. While I delete characters in firefox, it deletes two characters at once and the arrows (forward, upward, etc.) do not work at all. The forward delete is not working. Please help me. Thanks!

    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).<br />
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]<br />
    <br />
    If it does work in Safe-mode then disable all your extensions and then try to find which is causing it by enabling one at a time until the problem reappears.<br />
    You can use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.<br />
    You have to close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")

  • How to Avoid Special Characters in string

    Hai.
    I want only Alphabets & Digits to be entered in to my string.No any other special characters except spaces.How can I do this? 
    Solved!
    Go to Solution.

    MikeS81 wrote:
    see the attached example.
    I would allow a few more, e.g. 0 and 8 to allow editing of the entered string (backspace, cursor buttons, delete key, etc.).
    Message Edited by altenbach on 11-21-2008 12:49 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    check_char_LV80MOD.vi ‏14 KB
    FilterStringInput.gif ‏6 KB

  • Remove of non-printable characters from string

    Hi Gurus,
    How can I achive that? I have a string in which sign "end of line" occurss. How can I delete them?
    BR
    Marcin Cholewczuk

    Hi Marcin,
    Just use a [REPLACE|http://help.sap.com/abapdocu_70/en/ABAPREPLACE.htm] with a regular expression (Assuming variable STRING holds your data):
    replace all occurrences of regex '[\n\r]+' in STRING with ''.
    Note that I replaced newline ('\n') - also called end of line - and carriage return ('\r') with nothing (matching your delete request). This might not be wanted if you have a true multiline string. If you're more paranoid and want to cover more cases, you might want to replace any non-displayable characters using '\[\[:print:\]\]+' as your search pattern. So if you want to replace non-displayable characters with a space and just kill it at the end of the string you could use something like this:
    replace all occurrences of regex '[^[:print:]]+(?!$)' in STRING with ` `.
    replace all occurrences of regex '[^[:print:]]+$' in STRING with ''.
    Cheers, harald

  • How to accept only 4 or less hex characters in string control

    Hi,
    I want to accept only up to 4 hex characters in a string control. I dont want to use "hex display" property.
    How is it possible? I have String control key down? event in event case, I tried it with regular expressions [0-9a-fA-F]{4} but then I have to accept left, right, delete, backspace, home keys as well.
    Solved!
    Go to Solution.

    I agree with Dennis that you seem to be making life difficult for yourself.  However, you did ask the equivalent (as I understand it) "How can I allow the user to type "1", "2", "Ctrl-A", "B", "Ctrl-C", "D" and get this recognized as the string "12BD".  If you really want to do this, here is one way (I was lazy and left the answer as an array of 4 1-character strings).  I use PlatMods to exclude having any "modification" key other than Shift down, convert the numeric Char into a string, then count acceptable Hex letters and conditionally add them to the output array, stopping when I have 4 characters. 
    Bob Schor

Maybe you are looking for

  • CreatePDF Desktop Printer will no longer be available so how do I print a PDF from a scanned document????

    CreatePDF Desktop Printer will no longer be available so how do I print a PDF from a scanned document????

  • I would like to encrypt a PDF document

    Hello,      A problem came across my mind and I would to know if there is any solution. First of all I would like to know if there is any posibility for making a document mainly a pdf file unshareable, I don't point at copying the text from the docum

  • Connection pooling error (Tomcat 5.5 Oracle 9i)

    Can someone please help, For the last 3 hours been search all past thread but no luck with my issue. I get error on line 4: == mytest.jsp Context initContext = new InitialContext(); Context envContext = (Context)initContext.lookup("java:comp/env"); O

  • How to Retrieve Images from mysql on JSF page

    Hi, I want to retrieve all the images which are in my database(mysql) using Netbeans 6.9.1 on a JSF 2.0 page. How can i do so? I am using backing bean, i use backing bean methods in JSF. Pls help me... thanx...

  • VL10B picking wrong sales org.

    When we do a stock transport order, PO type ZUB, we ship from our plant to another plant. Each plant has it's own sales org. assigned to it. We use transaction VL10B to create the outbound delivery note.  We have 4 satellite plants that we will ship