Delete part of a string question

Hello I have this String 12a
I need to get a the value 12 of it an make it an int
But the problem is that I don't know what the string is it can be
12
or 12 a
or 12a
It is for people to fill in there house address and this is the number part.
The string is like this String number ="\"12a\"";
Is it possible to look for a letter in a String and delete it if you only want ints???

Try this on the command line. Dealing with java.lang.NumberFormatException in cases where the number is too large is left as an exercise.
Harald.
import java.util.regex.*;
* demonstrates use of <code>java.util.regex</code> to check if a
* string starts with digits.
public class bla {
   * thrown by {@link #getNumber} if the given string does not start
   * with digits.
  private static class BoomBoom extends Exception {
    public BoomBoom(String msg) {super(msg);}
   * reusable pattern to check for digits.
  private static Pattern p = Pattern.compile("[0-9]+");
   * convert leading digits of the parameter to an <code>int</code>
   * and return it.
   * @throws BoomBoom if the parameter does not start with digits.
  public static int getNumber(String s) throws BoomBoom {
    Matcher m = p.matcher(s);
    if( !m.lookingAt() ) {
      throw new BoomBoom("The string `"+s+"' does not start with "
                +"a positive number.");
    return Integer.parseInt(m.group(0));
  // don't clutter the javadoc
  private bla() {}
   * passes each command line argument through {@link #getNumber} and
   * prints the output or error to <code>System.out</code> or
   * <code>System.err</code> respectively.
  public static void main(String[] argv) {
    for(int i=0; i<argv.length; i++) {
      try {
     System.out.println("Your string `"+argv[i]
                  +"' starts with number "
                  +getNumber(argv));
} catch( BoomBoom e ) {
     System.err.println(e.getMessage());

Similar Messages

  • Replacing a part of a String with a new String

    Hi everybody,
    is there a option or a method to replace a part of a String with a String???
    I only found the method "replace", but with this method I only can replace a char of the String. I don't need to replace only a char of a String, I have to replace a part of a String.
    e.g.:
    String str = "Hello you nice world!";
    str.replace("nice","wonderfull");   // this won't work, because I can't replace a String with the method "replace"
                                        // with this method I'm only able to replace charsDoes anyone know some method like I need???
    Thanks for your time on answering my question!!
    king regards
    IceCube-D

    do check java 1.4 api, I think there is a method in it, however for jdk1.3 you can use
    private static String replace(String str, String word,String word2) {
         if(str==null || word==null || word2 == null ||
               word.equals("") || word2.equals("") || str.equals("")) {
              return str;
         StringBuffer buff = new StringBuffer(str);
         int lastPosition = 0;
         while(lastPosition>-1) {
              int startIndex = str.indexOf(word,lastPosition);
              if(startIndex==-1) {
                   break;
              int len = word.length();
              buff.delete(startIndex,startIndex+len);
              char[] charArray = word2.toCharArray();
              buff.insert(startIndex,charArray);
              str = buff.toString();
              int len2 = startIndex+word2.length();
              lastPosition = str.indexOf(word,len2);
         return buff.toString();

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

  • How Do I Mirror A Part Of A String?

    Dear Programmers,
    Does Anyone know how to mirror a string in C#:
    For example:  looks -> skool
    Thank you in advance,

    There is a Reverse method:
    string s = "looks";
    s = new string(s.Reverse().ToArray());
    Best way to reverse a string:
    http://stackoverflow.com/questions/228038/best-way-to-reverse-a-string
    And you can get a part of a string using the Substring method:
    https://msdn.microsoft.com/en-us/library/system.string.substring(v=vs.110).aspx
    Please remember to mark helpful posts as answer to close your threads and then start a new thread if you have a new question.

  • I have Iphone 5 and have an issue with deleting part of the messages in Imessage conversation. The trash button is not displayed to delete part of the imessage. I see only delete all option. Is it a bug?

    I have Iphone 5 and have an issue with deleting part of the messages in Imessage conversation. The trash button is not displayed to delete part of the imessage. I see only delete all option. Is it a bug?

    Hi An Iphone user,
    If you are having issues deleting a specific message from an iMessage conversation (not seeing the Trash icon), you may want to double-check that you are following the steps outlined in the following article:
    How do I delete a message?
    To delete a message, tap and hold the message bubble, then tap More.
    Tap Delete All to delete all the messages. Or tap to select the messages you want to delete, then tap .
    After you delete a message, you can recover it only by restoring from a backup.
    Send messages with your iPhone, iPad, or iPod touch - Apple Support
    Regards,
    - Brenden

  • Converting part of the string to a date and subtract with sysdate.

    HINT! In order solve this you must know how the pnr is assembled. Study this:
    650323-5510, we only need the first six characters. They inform us about when the person (car owner) was born. In this case it is 23 Mars 1965. You have to use several oracle built-in-functions to solve this. Hint! Begin by converting part of the string to a date and subtract with sysdate.
    select to_char(to_date(cast(pnr,'YYMMDDMM'))) from car_owner;
    please what am i doing wrong. i need the result to be something like this
    Hans, Rosenboll, 59,6 years.

    Hi.
    The main problem here is you have only last two digits of year. That could be the problem in a couple of years from now, when somebody born after 2k would get in to your database. For now if we ignore this problem the right solution would be :
    <code>
    SELECT months_between(trunc(SYSDATE),
    to_date('19' || substr('650323-5510',
    1,
    6),
    'YYYYMMDD')) / 12 years_old
    FROM dual
    </code>
    Suppose you are expecting the age of the car owner as a result above code will give you that. One again notice the '19' I appended.
    Best regards.

  • How do I delete part of a message conversation?

    I have to reboot my iPhone 5 to get the trash can to appear when I am trying to delete a part of a message conversation. Is there another way to delete part of a conversation? Using IOS 8.2.
    Thanks!

    If you do Get Info for the song - then (in Options tab, I think) amend the Start Time of the track so it's the point where the music starts. iTunes will permanently 'remember' your change.

  • How can you delete part of a message not the whole  conversation?

    How do you delete part of a message from a conversation on the new upgrade? You used to be able to click on the text, ticking it and then hit trash but thats gone. Please help!!

    click and hold on the bubble, you will now see "copy/more"   select 'more'
    you can now choose which bubbles to delete by selecting a check mark next to them and then hit trash can

  • How do i delete part of a song, ie spoken intro

    how do i delete part of a song already in my music library.  ie  the spoken intro to a song.  i want the song but not the spoken intro part.

    If you do Get Info for the song - then (in Options tab, I think) amend the Start Time of the track so it's the point where the music starts. iTunes will permanently 'remember' your change.

  • How can I delete part of my message or forward part of it? I only see an option that allows me to delete the entire message.... Help please

    How can I delete part of my message or forward part of it? I only see an option that allows me to delete the entire message.... Help please

    hold your finger on the part of the message you want to delete. This will give you the copy and more option. Choose more, and then you will be able to choose the message or messages you want to delete. Once selected you will be able to tap the trash can icon on the bottom of your screen.

  • Deleting parts of conversation in a message

    I have to reboot my iPhone 5 to get the trash can to appear when I am trying to delete a part of a message conversation. Is there another way to delete part of a conversation? Using IOS 8.2.
    Thanks!

    Thanks for your reply. I normally do exactly as you say. But for some reason the trash can fails to pop up after I check it and I can't use this method until I shut my phone off and reboot. Normally when looking at messages you see a camera, then iMesage block, then a microphone on the right bottom of the screen. When you hold down on a text bubble, click "More" then this bottom portion is replaced with a trashcan. This is not happening until I reboot and I don't know what is causing it. Hmm - bug?

  • How do you delete part of an app you downloaded

    how do i delete part of an app that i downloaded. do i have to delete the whole app and then reload what i want

    Possible with Adobe Acrobat, not Adobe Reader.

  • Ios7 how do u delete part of conversations on your text messages?

    since updating to ios7 a couple of days ago i cannot seem to work out how to delete part of conversations in your messages? not the whole message just part of the conversations like u used to be able to
    thanks

    Hold down the part of the message you want to delete. When you do that "copy/more" options will pop up. Click "more" and put a check mark next to the texts that you want to delete then click on the trash can in the lower left hand corner.

  • 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

  • Deleted part of library HELP!

    I accidentally deleted part of my library. not sure what i was doing but I still have the files in my documents. How do i get my music back on itunes?

    If you know where the files are, this is an easy fix.
    Open iTunes, and if you have all your music in one folder, you can choose "File -> Add Folder to Library..." in the menu.
    If all of your music is in seperate places, you'll have to seperately add inividual files using "File -> Add File to Library..." Add File to Library will only add up to four files at a time (shift-click to select multiple files).

Maybe you are looking for