Deleting Chars in a String.

I found some methods in the documantation which should work. like replace for example.
If I have, let's say the string "2 metres" and I want to cut off the " metres", i just write it like:
stringName.replace(" custom", ""); ?
But my compiler complains with: replace(char,char) in java.lang.String cannot be applied to (java.lang.String, java.lang.String... what am I doing wrong?

Thanks, that did help much. But now I have another
problem.. i want to convert an Int to a string and I
can't get it to work...
Stringname = valueOf(Integername);
That's what I thougt, but i get "cannot resolve
symbol. Method valueOf(int)....
Stringname = String.valueOf(Integername);/Kaj

Similar Messages

  • How to delete the last char in a String?

    i want to delete the last char in a String, but i don't want to convert the String to a StringBuffer or an array, who knows how to do?

    Try it in this way
    String MyString = "ABCDEF";
    MyString = MyString.substring(0,MyString.length()-1);

  • Deleting the last char of a string

    How can I Delete the last char of a string???
    example:
    asd@fdg@vvdfgfd@gdgdfgfd@gdfgdf@
    I want delete the last @!
    Tks in advance!

    hi,
    try this:
    lv_count = strlen(string).
    lv_count_last = lv-count - 1.
    replace string+lv_count_last(lv_count) in string by ' '.
    This should work.
    thnx,
    ags.
    Edited by: Agasti Kale on Jun 4, 2008 9:03 PM

  • Deleting last char in a string...

    I have a string that is created as follows: strBuffer += k.getKeyChar();(k is KeyPressed ...KeyEvent) How can I delete the last Char in the string strBuffer?

    Hi
    // simply substring
    if (strBuffer.length() > 1)
        strBuffer = strBuffer.substring(0, strBuffer.length()-1);
    // you may also use
    if (strBuffer.length() > 1)
        StringBuffer buffer = new StringBuffer(strBuffer).
                                   deleteCharAt(strBuffer.length()-1);
        strBuffer = buffer.toString();
    }I've not tested the above code myself & I've written the above code on the go after reading your query. The above code definitely work & help you.
    Regards,
    JPassion

  • Delete charaters from a string

    hi friends
    i want to delete all the charaters after ".". for example 200.00 to 200
    Regards

    I'd write this differenly now, but here's my old String utilities class...
    package krc.utilz;
    import java.util.regex.Pattern;
    import java.util.regex.Matcher;
    import java.util.List;
    import java.util.ArrayList;
    * Some handy String manipulation methods
    public abstract class Stringz {
       * returns the given string with the characters in the opposite order.
       * @param string String - the string to reverse.
       * @return String backwards.
      public static String reverse(String string) {
        return new StringBuffer(string).reverse().toString();
       * Returns the given string with the first letter in uppercase. Note that
       * the case of the rest of the characters in the string remains unchanged.
      public static String capitalise(String string) {
        return string.substring(0,1).toUpperCase() + string.substring(1);
       * returns a string of howMany spaces, or optionally a string of howMany ch's
      public static String spaces(int howMany) {
        return spaces(howMany, ' ');
      public static String spaces(int howMany, char ch) {
        if (howMany <= 0) return "";
        char[] chars = new char[howMany];
        for(int i=0; i<howMany; i++) chars=ch;
    return new String(chars);
    * right pad string to width
    * @param string String = the string to pad
    * @param width int = the desired width of the string
    * @return String the right-padded string.
    * @deprecated - just use String.format("%-${width}s", string);
    @Deprecated
    public static String padRight(String string, int width) {
    return String.format("%-"+width+"s", string);
    //return string + spaces(width - string.length());
    * left pad string to width
    * @param string String = the string to pad
    * @param width int = the desired width of the string
    * @return String the left-padded string.
    * @deprecated - just use String.format("%${width}s", string);
    @Deprecated
    public static String padLeft(String string, int width) {
    return String.format("%"+width+"s", string);
    //return spaces(width - string.length()) + string;
    * find the first token in a string starting at start. think strpbrk.
    * For example<code>
    * String xml = "<tag attr="value">content</tag>"
    * int x = firstOf(xml, " >");
    * System.out.println(x>0 ? s.substring(1,x) : "UNKNOWN");
    * </code>
    * Produces:<code>tag</code>
    * @param string String = the string to search
    * @param tokens String = a logical array of chars to seek
    * @param OPTIONAL start int = start searching string here
    * @return the index of the fist occurence in string of the first found
    * char in tokens, else (no tokens where found) returns -1;
    public static int firstOf(String string, String tokens) {
    for(int i=0; i<string.length(); i++) {
    char ch = string.charAt(i);
    for(char token : tokens.toCharArray()) {
    if (ch==token) return i;
    return -1;
    public static int firstOf(String string, String tokens, int startIndex) {
    return Stringz.firstOf(string.substring(startIndex), tokens);
    * Returns the prefix of the given string which proceeds the first occurrence
    * of any of the given tokens... optionally starting at the given startIndex.
    * <p>
    * For example<code>
    * System.out.println(substring("<tag attr=\"value\">content</tag>", "< >"));
    * </code>produces<code>tag</code>.
    * @param string String - the string to search
    * @param tokens String - a list of chars which serve as end markers
    * @param start int - OPTIONAL start searching string here, 0 based.
    * @return String string[start..token-1], else the empty string
    public static String prefixOf(String string, String tokens) {
    int end = Stringz.firstOf(string, tokens);
    return end==-1 ? "" : string.substring(0,end);
    public static String prefixOf(String string, String tokens, int startIndex) {
    return(Stringz.prefixOf(string.substring(startIndex), tokens));
    * Splits the given string into chunks of the given size.
    * @param string String - The string to split up.
    * @param size it - The size of each chunk.
    public static String[] chunk(String string, int size) {
    Pattern pattern = Pattern.compile(".{1," + size + "}");
    Matcher matcher = pattern.matcher(string);
    List<String> result = new ArrayList<String>();
    while ( matcher.find() ) {
    result.add(matcher.group());
    return result.toArray(new String[result.size()]);
    Edited by: corlettk on 3/08/2008 10:54 - gave up chasing dependencies - just post the whole class.

  • Option Special functions - Delete char. w. vals is disable

    Hello Experts,
    I am trying to remove characteristics assignment from class, but it is not allowing me to do so.
    And asking for use option "Special functions -> Delete char. w. vals " , but option is disabled when I open class data with change mode and select characteristics to be deleted.
    Query 1 : How to enable this option?
    Another option, to run report 'RMCLMDEL' to remove characteristics assignment from class, but I would like to know
    Query 2 : is there any precaution to take before running this report, will running this report have any inconsistency.
    Thanks in advance
    Thanks,
    Sam.

    Hi Samir,
    Kindly check the values maintained in dependancies , first remove those. Also remove the characteristics from all the classes wherver used. Then you will be able to delete it.
    Hope this will resolve the query.
    Regards,
    Ravindra

  • 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.

  • Finding last char in the string

    Hi
    i need to find out whether the last char of a string is '/' (forward slash). please let me know if there's a FM to do that. Other post me the logic for this ASAP.
    thanks

    len = strlen(char).
    len = len - 1.
    if char+len(1) = '/'.
      *write ur code
    endif.
    chk this code
    REPORT ychatest.
    DATA : str(5) VALUE '123/',
           len TYPE i.
    len = STRLEN( str ).
    len = len - 1.
    IF str+len(1) = '/'.
      WRITE : '/ found'.
    ENDIF.
    <b>Reward points if helpful and close thrad if solved</b>
    Message was edited by: Chandrasekhar Jagarlamudi

  • Compare individual char of 2 string

    Hi
    I need to compare the each individual char of 2 string.
    String a = "Ae12";
    String b = "aE12";
    // I tried the followings:
    // a
    String c = a.substring(0,0);
    String d = a.substring(1,1);
    String e = a.substring(2,2);
    String f = a.substring(3,3);
    // b
    String c1 = b.substring(0,0);
    String d1 = b.substring(1,1);
    String e1 = b.substring(2,2);
    String f1 = b.substring(3,3);
    if(c.equalsIgnoreCase(c1)&&d.equalsIgnoreCase(d1)&&e.equalsIgnoreCase(e1)&&f.equalsIgnoreCase(f1)) // Cannot be compared
    // and I tried the followings:
    // a
    char c = a.charAt(0);
    char d = a.charAt(1);
    char e = a.charAt(2);
    char f = a.charAt(3);
    // b
    char c1 = b.charAt(0);
    char d1 = b.charAt(1);
    char e1 = b.charAt(2);
    char f1 = b.charAt(3);
    if(c==c1&&d==d1&&e==e1&&f==f1) // cannot be compared.
    Both cases cannot be compared. How can I fix it?
    Because I want to compare those 2 strings without case sensitive and numbers.
    Thanks

    techissue2008 wrote:
    String a = "Ae12";
    String b = "aE12";
    Then, are "Ae12" and "aE12" the same when ignore case?
    If so, the Strings are actually the same.No, the Strings are not the same, if by same, you mean the "same" Object, or the "same" value when case is not ignored, but they are the "same" value when case is ignored.
    This prints true (try it yourself), as it should
    public class Test {
      public static void main (String[] args) {
        System.out.println("aE12".equalsIgnoreCase("Ae12"));
    }They are still two distinct instances with two distinct values however, so where, exactly, is your problem?

  • Finding char in a string

    Hi,
    In C there is a function strchr() to find a char in a string. Is there an equivalent funtion in Java?
    The function indexOf() returns an int, but I want this char search would return a boolean value.
    So help please, thanks a lot
    chanh

    public boolean strchr(char myChar, String myString){
       for(int j = 0; j < myString.length(); j++){
          if(myChar == myString.charAt(j) return true;
       return false;
    }Is this what you are looking for?

  • 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 invoke the char " in a string?

    Hi!
    I�m trying to invoke the char " in a string and I can�t think of any good way to do that.
    plz help.

    use
    String foo = new String("the string foo has the \"a string\" value");

  • How to take last 5 char from a string

    Hi All
    I have a requirement,
    base on some comp i have to populate another field.
    in this case i have compare last 3 char of a string 
    example if total string say asasdffrx i have to take last three char here it is frx.
    always i have to last 3 char.
    i can use +6(3) but it wont work every time because string lenght is not fix for all vaue.
    thanks

    Hi,
    A.H.P sample is ok but insert additional check for strigs shorter than 3 (to avoid negative offset):
    data : n TYPE I.
    n = STRLEN( zfield ) - 3.
    if n >= 0.
    result = zfield+n(3).
    else.
    result = zfield.
    endif.
    Krzys

  • How to delete char index.

    Hello everyone
    I am having bit of problem to remove an index of letters[] (char array)
    the letters [] consists of letters from a-z..i.e.
    letters[0]= a
    letters[1]=b
    ..... and so on
    now I have a method which has param of char
    void
    public String unGuessedLetters(char letter)
    String str;
    for(int i=0;i<=25;i++)
    if(letter==letters)
    letters.deleteCharAt(i);
    str= new String (letters);
    return str;
    for some reason this is not working, even after importing the java.lang.*; . Please guys any help will be highly appreciated.
    Thanks
    Edited by: sifatk on Sep 29, 2007 7:30 AM

    public String unGuessedLetters(char letter)
        String str;
        for(int i=0;i<=25;i++)
            if(letter==letters)
    letters.deleteCharAt(i);
    str= new String (letters);
    return str;
    I think this is your code. When posting use the "code" tags. The idea is you put [[i]code] at the start of your code and [/code] at the end - including the square brackets.  It is a good idea to use spaces instead of tabs to indent code.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • 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

Maybe you are looking for

  • SSIS package give an error if execute through SQL server agent

    I have created a SSIS package in BIDS 2012. If i execute this package through sql server agent it gives the below error: Executed as user: NT Service\SQLSERVERAGENT. Microsoft (R) SQL Server Execute Package Utility  Version 11.0.2100.60 for 64-bit  C

  • Tv shows and iphone

    i have purchased and downloaded 2 tv shows to my itunes and havew everything checked that should work , but cannot get them to transfer to my 32g 3gs, have tried multipule ways with no joy , please somebody tell me what i am doing wrong , thanks

  • No Audio When Converting Videos For iPod

    whenever i convert video files for my ipod they do not have audio. i have tried several programs, and none work. i have read other discussions about this, and found that MPEG Streamclip worked for other people, however whenever i try to convert using

  • Importing graphics from photoshop resolution issues

    Hi, I'm new at final cut but I'm having an issue with a graphic that I imported from photoshop. The image is 300 dpi : 2896 pixels by 2175 pixels. I saved it as a targa file with an alpha channel to mask the graphic. The image looks horrible "quality

  • My video camera button where i can record my own video is missing.pls help!

    On camera button.the video recording is missing.pls help where is it now?