Remove one char from a string

What is is the easiest and fastest way to delete a single character from somewhere in a string?
I have both the char and the index in the string of the char easily available, but there doesn't seem to be a String.remove(int charIndex) method which I really want. Any tips? Thanks.

"Easiest" and "fastest" are relative to what? Here's a couple of ways:String newString = oldString.substring(0, index) + oldString.substring(index+1);
String newString = (new StringBuffer(oldString)).deleteCharAt(index).toString();I'm sure there are many other ways.
PC²

Similar Messages

  • How to remove empty char from a string

    Hi,
    In my code I should get numeric int numbers and convert them to 1 and 0 , concatenate thm to make an string ( 8 chars) . the problem I have is the empty chars as result of conversion from number to string
    so lets say pxiAnaIn=1 dutVdd=2 and dutOut=5 so then the output should be 10110001 but now the output is 10110  1 . could you please let me know how can I fix this problem
    thanks

    tintin_99 wrote:
    Hi,
    In my code I should get numeric int numbers and convert them to 1 and 0 , concatenate thm to make an string ( 8 chars) . the problem I have is the empty chars as result of conversion from number to string
    so lets say pxiAnaIn=1 dutVdd=2 and dutOut=5 so then the output should be 10110001 but now the output is 10110  1 . could you please let me know how can I fix this problem
    thanks
    You could make your life a little easier and only use 1 format string.  Use "%03b%02b%03b" for the format string.  You can then expand the format string to allow multiple inputs.  You will do the job of 4 functions with just 1.
    "%3b" just says to give 3 spaces for the binary number.  But any preceding 0s will be turned into spaces.  Adding the 0 in there tells the format string to prepend 0s instead of using spaces.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Remove unwanted chars from a string

    hi friends,
    mi special requirement is this:
    i have a string containing:
    "Jose[12] M[36]ller" and i only want to see [12][36] afterwards, so how could i remove the remaining characters ?
    Thank you!

    Hi Clemens,
      if u only want the data enclosed in the parentheses[] along with the parentheses then this program will work fine for you.  Check the same and get back to us. If u can elaborate ur reqmt then we can help in a better way.
    REPORT  zyh284_test2.
    DATA:
    w_string TYPE string VALUE 'Jose[12] M[36]ller',
    w_sub_string TYPE string,
    w_int TYPE i,
    w_char,
    w_counter TYPE i,
    fl_flag.
    w_int = STRLEN( w_string ).
    w_counter = 0.
    DO w_int TIMES.
      w_char = w_string+w_counter(1).
      IF w_char EQ '['.
        fl_flag = 'X'.
      ENDIF.
      IF fl_flag = 'X'.
        CONCATENATE  w_sub_string w_char INTO w_sub_string.
      ENDIF.
      IF w_char EQ ']'.
        CLEAR fl_flag.
      ENDIF.
      w_counter = w_counter  + 1.
    ENDDO.
    WRITE:w_sub_string.

  • How to remove the Char.from one Operating Concern

    Hi Guys,
    How to remove the Char. from one Operating Concern.
    I have created one Char. (WWDOC) and moved to Operating Concern (OOCC). Operating Concern is in red status.
    Now, i want to remove that new assigned Char. (WWDOC)from the operating concern (OOCC). I did't find any option in the menu also.
    Appreciate your help.....
    T&R
    VVR

    Hi Sasi,
    Iam not able to push back that char. from my operating concern. In help it is given you have to delete the data contents in the table before pushing back. Please let me know if any other option available.
    Thanks for your reply.
    VVR

  • How to remove HTML tags from a String ?

    Hello,
    How can I remove all HTML Tags from a String ?
    Would you please to give me a simple example ?
    Best regards,
    Eric

    Here's some code I cooked up. I have created an object that processes code so that it can be incorporated directly into a project. There is some redundancy so that the it can be used in more than one way. Depending on your situation you might have to make the condition statement a little more sophisticated to catch stray ">" tags.
    I have also included a Tester application.
    //This removes Html tags from a String either by submitting the String during construction and then
    // calling getProcessedString() or
    // by simply calling " stringwithoutTags=removeHtmlTags(stringWithTagsSubmission); "
    //Note: This code assumes that all"<" tags are accompanied by a ">" tag in the proper order.
    public class HtmlTagRemover
         private String stringSubmission,processedString,stringBeingProcessed;
         private int indexOfTagStart,indexOfTagEnd;
         public HtmlTagRemover()
         public HtmlTagRemover(String s)
              removeHtmlTags(s);          
         public String removeHtmlTags(String s)
              stringSubmission=s;
              stringBeingProcessed=stringSubmission;
              removeNextTag();
              return processedString;
         private void removeNextTag()
              checkForNextTag();
              while((!(indexOfTagStart==-1||indexOfTagEnd==-1))&<indexOfTagEnd)
                   removeTag();
                   checkForNextTag();
              processedString=stringBeingProcessed;
         private void checkForNextTag()
              indexOfTagStart=stringBeingProcessed.indexOf("<");
              indexOfTagEnd=stringBeingProcessed.indexOf(">");
         private void removeTag()
              StringBuffer sb=new StringBuffer("");
              sb.append(stringBeingProcessed);
              sb.delete(indexOfTagStart,indexOfTagEnd+1);
              stringBeingProcessed=sb.toString();
         public String getProcessedString()
              return processedString;
         public String getLastStringSubmission()
              return stringSubmission;
    public class HtmlRemovalTester
         static void main(String[] args)
              String output;
              HtmlTagRemover h=new HtmlTagRemover();
              output="The processed String: "+h.removeHtmlTags("<Html tag>This is a test<another Html tag> string<yet another Html tag>.");
              output=output+"\n"+" The original string:"+h.getLastStringSubmission();
              System.out.print(output);

  • Remove regular expression from a string

    Hello,
    I have a string like this
    @1test;'"{input+
    Please help me to remove special characters from the string.

A: remove regular expression from a string

Hi Krishna,
DATA : str TYPE STRING VALUE '@1test;"{}]input+',
            char,
            length TYPE i,
            index TYPE i.
length = STRLEN( str ).
WHILE length > index.
  char = str+index(1).
  WRITE char.
  if char CA '+-*/!`@#$%^&()_=[]{};'.               " Add/Remove here to include numbers
    REPLACE ALL OCCURRENCES OF char in str WITH ''.
    REPLACE ALL OCCURRENCES OF '"' in str WITH ''.  " characters "{}[] are not comparable
    REPLACE ALL OCCURRENCES OF '{' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '}' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '[' in str WITH ''.
    REPLACE ALL OCCURRENCES OF ']' in str WITH ''.
    length = STRLEN( str ).
    ENDIF.
  add 1 to index.
ENDWHILE.
WRITE str.
Add or remove special char from '+-*/!`@#$%^&()_=[]{};' in if part as per your requirement.
Hope it meets your requirement.
Do not forget to mark helpful/correct if ma answer is useful .
Thanks,
Karthik

Hi Krishna,
DATA : str TYPE STRING VALUE '@1test;"{}]input+',
            char,
            length TYPE i,
            index TYPE i.
length = STRLEN( str ).
WHILE length > index.
  char = str+index(1).
  WRITE char.
  if char CA '+-*/!`@#$%^&()_=[]{};'.               " Add/Remove here to include numbers
    REPLACE ALL OCCURRENCES OF char in str WITH ''.
    REPLACE ALL OCCURRENCES OF '"' in str WITH ''.  " characters "{}[] are not comparable
    REPLACE ALL OCCURRENCES OF '{' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '}' in str WITH ''.
    REPLACE ALL OCCURRENCES OF '[' in str WITH ''.
    REPLACE ALL OCCURRENCES OF ']' in str WITH ''.
    length = STRLEN( str ).
    ENDIF.
  add 1 to index.
ENDWHILE.
WRITE str.
Add or remove special char from '+-*/!`@#$%^&()_=[]{};' in if part as per your requirement.
Hope it meets your requirement.
Do not forget to mark helpful/correct if ma answer is useful .
Thanks,
Karthik

  • How can I remove one page from adobe file

    How can I remove one page from adobe file, when I try to remove the page a dialgue box say "some pages are being used, so they can not be ereased"?

    Tools>Pages>Delete pages

  • Remove HTML tags from a string

    I have a string that contains a couple of HTML or XHTML tag, for example
    lv_my_string = '<p style="something">Hello <strong>World</strong>!</p>'.
    For a special use case, I want to remove all HTML from that string and process only the plain text
    lv_my_new_string = 'Hello World!'.
    Is there any method, function module, XSLT or anything else for that already?

    Hi Daniel,
    I tried using the FM (SWA_STRING_REMOVE_SUBSTRING) but I guess it is expecting a particular pattern which is not so apparent in your case. Iu2019ve written a small piece of code which you can try using in a FM or a PERFORM and that should do the trick. Please let me know if you have any questions.
    PARAMETER: P_LINE(100).
    TYPES: BEGIN OF TY_LINE,
             LINE(100),
           END OF TY_LINE.
    DATA: T_LINE TYPE STANDARD TABLE OF TY_LINE,
          WA_LINE LIKE LINE OF T_LINE.
    DATA: W_LINE(100),
          W_LEN(100),
          W_COUNT TYPE I,
          W_FLAG,
          W_FLAG1,
          W_I TYPE I.
    W_COUNT = STRLEN( P_LINE ).
    DO W_COUNT TIMES.
      IF P_LINE+W_I(1) = '<'.
        W_FLAG = 1.
        W_I = W_I + 1.
        IF NOT WA_LINE-LINE IS INITIAL.
          APPEND WA_LINE-LINE TO T_LINE.
          CLEAR WA_LINE.
        ENDIF.
        CONTINUE.
      ELSEIF P_LINE+W_I(1) = '>'.
        W_FLAG = 0.
        W_I = W_I + 1.
        CONTINUE.
      ENDIF.
      IF W_FLAG = 1.
        W_I = W_I + 1.
        CONTINUE.
      ELSE.
        CONCATENATE WA_LINE-LINE P_LINE+W_I(1) INTO WA_LINE-LINE.
        W_I = W_I + 1.
      ENDIF.
    ENDDO.
    LOOP AT T_LINE INTO WA_LINE.
      CONCATENATE W_LINE WA_LINE-LINE INTO W_LINE SEPARATED BY SPACE.
    ENDLOOP.
    SHIFT W_LINE LEFT DELETING LEADING SPACE.
    WRITE: W_LINE.
    Input:
    <p style="something">Hello <strong>World</strong>!</p>
    Output:
    HELLO WORLD !
    Regards,
    Pritam

  • Removing leading zeros from a string value

    Hi All,
    i have a Requirement like , i need remove leading zeros from a string value,
    like , 00Raj00Shekar==>Raj00shekar,
    how can i do this ?
    if it is only with the custom functions ,where can add the fuction in Jdeveloper and SOA Middle ware?
    Thanks in Advance,
    Raj

    Hi Raj,
    you can use below function to get the desired output in xsl.
    <xsl:value-of select='translate(oraext:left-trim(translate(<inpString>,"0"," "))," ","0")'/>
    HTH,
    Regards,
    Vikas Manchanda

  • How to get a char from a String Class?

    How to get a char from a String Class?

    Use charAt(int index), like this for example:
    String s = "Java";
    char c = s.charAt(2);
    System.out.println(c);

  • How to  Remove the  Spc Char from a String ?

    Hi
    I am trying to stream out the file name after useing Timestamp. It throws some exception
    So I used the trim method for remove the space and spacial charater. But does't trim even space also.
    Please any body help me how to remove the space and spceial characters from my string.
    The file name ( String of value)
    2c5e773bad5e153cf91d7adabc121e62007-03-30 21:54:43.219.ivwr
    the file name after removing will be like this
    d2c5e773bad5e153cf91d7adabc121e620070330215443.ivwr
    pls help me
    Thanks,
    Merlin Roshina

    filename = filename.replaceAll("(?!\\.ivwr$)[- :.]","");

  • Removing Null values from character string

    Hi All,
    Can i remove NULL values (hexadecimal - 0000) from character string. I am uploading a file from presentation layer (shared server) and getting NULL values in many fields which i want to remove.
    please assist.
    Thanks for you help..
    Regards,
    Mohaiyuddin

    Hi,
    Most likely, nobody needed it, but if anybody in future will need the solution for related problem  - here's solution:
    data: lv_nullchar type xstring value '0'.
    shift lv_xstring right deleting trailing lv_nullchar in byte mode.
    shift lv_xstring left deleting leading lv_nullchar in byte mode.
    This hack deleting null chars in lv_xstring at end file and at begining of file. Works perfect for me, where i also worked with files.

  • HT5622 How can I remove one phone from my apple id and create a new apple id for that phone

    How can I remove just one phone from my apple id and create a new apple id for just that phone

    Follow the Checklist here
    What to do before selling or giving away your iPhone, iPad, or iPod touch
    Then set up the Phone as New using the preferred Apple ID.
    Create one at My Apple ID

  • Remove one version from web gallery album

    I created a mobile me gallery in aperture. AFter doing it, i decided to add copyright to the images in photoshop. I did this with apertures ability to edit with an external editor. I completed it all and went back into to aperture happy to se there were now two versions of each photo, one with the change, one without.
    However, on the mobile me gallery folder, each picture has a stack of two pictures, one with the edit one without etc. How can I remove the original from the mobile me gallery but keeping it in aperture?
    i seem to remember seeing an option when I right clicked somewhere and I could choose to remove an image from an album, but I can't find this..
    Regards

    Ok i tried that an the version I wanted got a tick at the top centre of the thumbnail. I synced the gallery but it didn't really work.
    The thumbnails in the web gallery have the copyright in the bottom right but when you click it to load the large version, it loads without the copyright.
    Have a look
    http://gallery.me.com/alexdlyons#100265&view=grid&bgcolor=black&sel=3
    I unstacked one of the photos and found the remove from album button. I tried this and I was left with the one I wanted, so I did it to all of them. I tried to sync it but no joy. Now I am left with the original project in bits as there are some versions with weird names, some with copyright etc and with OCD it is wrecking my head!!
    How can I fix this??
    Regards

  • How to remove last char in a string by space

    I have to implement backspace application(remove a last char in a string , when we pressed a button).
    for ex: I enter the no
    1234
    instead of 1236
    So when i press a button on the JWindow... it should display
    123
    so that i can enter 6 now.
    I tried to display the string "123 " instead over "1234" but it is not working when the no background is specified. but works fine when a background color is specified.
    The string is displayed as
    Graphics2D g = (Graphics2D)window.getGraphics();
    AttributedString as = new AttributedString(string, map);
    g.drawString(as.getIterator(),x,y);
    In the map, the background is set to NO_BACKGROUND.
    Thanks and regards

    Deja vu. I saw this kind of post before, and I'm sure
    it was today.http://forum.java.sun.com/thread.jspa?threadID=588110&tstart=0
    Here it is.

  • Maybe you are looking for