Removing characters from string after a certain point

Im very new to java programming, so if this is a realy stupid question, please forgive me
I want to remove all the characters in my string that are after a certain character, such as a backslash. eg: if i have string called "myString" and it contains this:
109072\We Are The Champions\GEMINI
205305\We Are The Champions\Queen
4416\We Are The Champions\A Knight's Tale
a00022723\We Are The Champions\GREEN DAYi would like to remove all the characters after the first slash (109072*\*We...) leaving the string as "109072"
the main problem is that the number of characters before and after is not the always the same, and there is often letters in the string i want, so it cant be separated by removing all letters and leaving the numbers
Is there any way that this can be done?
Thanks in advance for all help.

You must learn to use the Javadoc for the standard classes. You can download it or reference it on line. For example [http://java.sun.com/javase/6/docs/api/java/lang/String.html|http://java.sun.com/javase/6/docs/api/java/lang/String.html].

Similar Messages

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

  • Remove "&" charachter from string

    Hi,
    Please inform me how can i remove the & from string.
    i try this but not working.
    SELECT REGEXP_REPLACE(’raise the level of &performance, creativity',’&','') COL1 FROM DUAL;
    Also i want to remove any special character from statement.
    many thanks

    Ayham wrote:
    i try this but not working.
    SELECT REGEXP_REPLACE(’raise the level of &performance, creativity',’&','') COL1 FROM DUAL;Are you getting any error?
    SQL> set define off
    SQL> SELECT REPLACE('raise the level of &performance, creativity','&') COL1
      2  FROM DUAL;
    COL1
    raise the level of performance, creativity>
    Also i want to remove any special character from statement.
    Search the forum..
    Sample:Re: How to find Special Characters in a single query
    Edited by: jeneesh on Sep 17, 2012 12:26 PM

  • Gain control freezes after a certain point (cannot get highlights to 100) with colorwheel mode

    I just purchased Adobe CC, (Switching from FCP 7, did not want to upgrade to FCP X).  Really loving SpeedGrade (was an Apple color user)
    I am using a standard iMAC keyboard and magic mouse (iMAC 27")
    In colorwheel mode:  After setting the blacks to 0 with the offset wheel, I try to move the gain wheel to the right, to get my highlights to 100.  Even when holding shift, I have to click and drag several times to move the pointer.  I cannot move it in one motion.  Even then, the pointer will literally stop or "freeze" at about the 3 o'clock position.  In order to get my highlights to 100, I have to switch to the Editbox mode and scroll the numbers up manually.  I cannont do it with the colorwheel mode.
    Very frustrating.  Any advice?

    Thank you so much for your prompt response.  After I posted my question, I looked online and found some users had the exact same issue and found the solution.  It is in the way you move the mouse:
    When clicking on the indicator for a color wheel, my impulse was to move the mouse in a downward circular motion, to mimic the round path of the wheel.  This appears to not work and makes the indicator "freeze" after a certain point.
    When clicking on the indicator and then moving the mouse laterally, directly to the left or right on a mouse pad (or desk), it moves the color wheel indicator all the way down to either end.  When moving the mouse this way, it seems to work.  I hope I’m explaining this clearly.
    To answer your question, yes the issue was with the Offset and Gamma wheels as well.  But since the particular adjustment for these was not as much, I didn't realize it.  But the gain adjustment I was doing was more severe, which is why I thought it was just the gain wheel adjustment.
    So it appears it was the way you move the mouse to adjust the color wheel - which should be left and right.
    I really am enjoying Speedgrade much more than Color.  I was a huge Color fan as well and very upset when Apple discontinued it.  I am very happy I found SpeedGrade and look forward to learning it more in depth.  My next challenge is to find out how to use the SG color wheel controls to mimic curve adjustments.

  • Removing extra text after a certain point for a field

    Post Author: ralph.devlin
    CA Forum: Formula
    Hello,
    What we want to do is remove extra text, IE (PO12345.195) We would want to remove the .195 from the end of that data so that the groupings will group them correctly. How can I accomplish this. The defaul trim commands seem to only elimnate white space, I want to elimnate text up to a certain point. thanks
    Ralph

    Post Author: Charliy
    CA Forum: Formula
    You want to do an INSTR to locate the period, then a LEFT to only show the data before it.  Something like:
    IF INSTR({table.field},".") > 0 THEN LEFT({table.field},(INSTR({table.field},".") )-1) ELSE {table.field}
    I subtracted 1 because in your example above the period is in position 8 and you want the first 7 characters.

  • Remove $%&* characters from a String

    Hi,
    I have the following program that is supposed to detect a subsequence from a String (that contains $ signs) and remove it. This is a bit tricky, since because of $ signs, the replaceAll method for String does not work. When I use replaceAll for removing the part of the String w/ no $ signs, replaceAll works perfectly, but my code needs to cover the $ signs as well.
    So far, except for replaceAll, I have tried the following, with the intent to first remove $ signs from only that specific sequence in the String (in this case from $d $e $f) and then remove the remaining, which is d e f.
    If anyone has any idea on this, I would greatly appreciate it!
    Looking forward to your help!
    public class StringDivider {
         public static void main(String [] args)
              String symbols = "$a $b $c $d $e $f $g $h $i $j $k l m n o p";
             String removeSymbols = "$d $e $f";
             int startIndex = symbols.indexOf(removeSymbols);
             int endIndex = startIndex + removeSymbols.length()-1;
             for(int i=startIndex;i<endIndex+1;i++)
                  if(symbols.charAt(i)=='$')
                       //not sure what to do here, I tried using replace(oldChar, newChar), but I couldn't achieve my point, which is to
                       //delete $ signs from the specific sequence only (as opposed to all the $ signs)
             System.out.println(symbols);
    }

    A little modification on the last version:
    This one's more accurate.
    public class StringDivider {
         public static void main(String [] args){
              String symbols = "$a $b $c $d $e $f $g $h $i $j $k l m n o p";
                  String removeSymbols = "$d $e $f $g";
                  if(symbols.indexOf(removeSymbols)!=-1)
                       if(removeSymbols.indexOf("$")!=-1)
                            removeSymbols = removeSymbols.replace('$', ' ').trim();
                            removeSymbols = removeSymbols.replaceAll("[ ]+", " ");
                            String [] symbolsWithoutSpecialChars = removeSymbols.split(" ");
                            for(int i=0;i<symbolsWithoutSpecialChars.length;i++)
                                 symbols = symbols.replaceAll("[\\$]*"+symbolsWithoutSpecialChars, "");
                             symbols = symbols.replaceAll("[ ]+", " ");
                   else
                        symbols = symbols.replaceAll(removeSymbols, "");
              symbols = symbols.trim();
              System.out.println(symbols);

  • Removing characters from a String (concats, substrings, etc)

    This has got me pretty stumped.
    I'm creating a class which takes in a string and then returns the string without vowels and without even numbers. Vowels and even characters are considered "invalid." As an example:
    Input: "hello 123"
    Output: "hll 13"
    The output is the "valid" form of the string.
    Within my class, I have various methods set up, one of which determines if a particular character is "valid" or not, and it is working fine. My problem is that I can't figure out how to essentially "erase" the invalid characters from the string. I have been trying to work with substrings and the concat method, but I can't seem to get it to do what I want. I either get an OutOfBoundsException throw, or I get a cut-up string that just isn't quite right. One time I got the method to work with "hello" (it returned "hll") but when I modified the string the method stopped working again.
    Here's what I have at the moment. It doesn't work properly for all strings, but it should give you an idea of where i'm going with it.
    public String getValidString(){
              String valid = str;
              int start = 0;
              for(int i=0; i<=valid.length()-1; i++){
                   if(isValid(valid.charAt(i))==false){
                             String sub1 = valid.substring(start, i);
                             while(isValid(valid.charAt(i))==false)
                                  i++;
                             start=i;
                             String sub2 = valid.substring(i, valid.length()-1);
                             valid = sub1.concat(sub2);
              return valid;
         }So does anybody have any advice for me or know how I can get this to work?
    Thanks a lot.

    Thansk for the suggestions so far, but i'm not sure how to implement some of them into my program. I probably wasn't specific enough about what all I have.
    I have two classes. One is NoVowelNoEven which contains the code for handling the string. The other is simply a test class, which has my main() method, used for running the program.
    Here's my class and what's involved:
    public class NoVowelNoEven {
    //data fields
         private String str;
    //constructors
         NoVowelNoEven(){
              str="hello";
         NoVowelNoEven(String string){
              str=string;
    //methods
         public String getOriginal(){
              return str;
         public String getValidString(){
              String valid = str;
              int start = 0;
              for(int i=0; i<=valid.length()-1; i++){
                   if(isValid(valid.charAt(i))==false){
                             String sub1 = valid.substring(start, i);
                             while(isValid(valid.charAt(i))==false)
                                  i++;
                             start=i;
                             String sub2 = valid.substring(i, valid.length()-1);
                             valid = sub1.concat(sub2);
              return valid;
         public static int countValidChar(String string){
              int valid=string.length();
              for(int i=0; i<=string.length()-1; i++){
                   if(isNumber(string.charAt(i))==false){
                        if((upperVowel(string.charAt(i))==true)||lowerVowel(string.charAt(i))){
                             valid--;}
                   else if(even(string.charAt(i))==true)
                        valid--;
              return valid;
         private static boolean even(char num){
              boolean even=false;
              int test=(int)num-48;
              if(test%2==0)
                   even=true;
              return even;
         private static boolean isNumber(char chara){
              boolean number=false;
              for(int i=0; i<=9; i++){
                   if((int)chara-48==i){
                        number=true;
              return number;
         private static boolean isValid(char chara){
              boolean valid=true;
              if(isNumber(chara)==true){
                   if(even(chara)==true)
                        valid=false;
              if((upperVowel(chara)==true)||(lowerVowel(chara)==true))
                   valid=false;
              return valid;
    }So in my test class i'd have something like this:
    public class test {
    public static void main(String[] args){
         NoVowelNoEven test1 = new NoVowelNoEven();
         NoVowelNoEven test2 = new NoVowelNoEven("hello 123");
         System.out.println(test1.getOriginal());
         //This prints hello   (default constructor string is "hello")
         System.out.println(test1.countValidChar(test1.getOriginal()));
         //This prints 3
         System.out.println(test1.getValidString());
         //This SHOULD print hll
    }

  • Removing unwanted from string

    I am trying to remove unwanted from a string. For example:
    String is "boy the movie part 2 (2009)". from this string i wanted to remove "(2009)" only, so my string can be looked like as "boy the movie part 2".
    Please provide me logic to do this.
    Thanks,
    Amol

    gimbal2 wrote:
    Hey if that's all you need:
    [snip]
    Just substring minus the last six characters and to not have to make any assumptions about whitespace being present in the result, a trim() is added for the fun of it.
    This is absolutely not fail proof, but it does what you ask.@OP: Most likely this is not what you really want. However, as gimbal2 points out, it does what you ask. The lesson is, you need to be clear and precise in expressing your requirements. To drive the point home, here is some more code that does what you asked for, but probably not what you really want it do do.
    if (str.equals("boy the movie part 2 (2009)") {
      str = "boy the movie part 2";
    }

  • Remove Mail from mailbox after accepting mail by another guy

    I have an requirement in such way that if one employee accpets the mail, mail should get removed from mail box of other employee.
    Mail are the MS-Outlook mails and all employee are group together in one address book.
    In second scenario, if employee sent one mail (For ex. Leave application) it goes to two high level. If first level try to approve it at time it should prompt error message that second level approval is pending.
    Please let me know is it possible through ABAP or workflow?
    Thanks in stack

    Hi Nilesh,
    <i>at first I don't really have very good news for you:</i>
    Removing mails from Outlook is a microsoft feature and does only work when developing an appropriate application for this one. Removing mail items also prerequesites that an Outlook template/form is used and it is not a "mail" object anyways.
    Solving the problem this way would possibly exceed any one's project's budget.
    <i>The better news is:</i>
    What you might think about is the Outlook-Connector for SAP which comes with the Frontend-CD that opens up in a separate "inbox", which refreshes from the SAP's workitem inbox. If a certain workitem disappears it will also disappear (after the refresh time) from the outlook's inbox as well.
    As I have said in one of my posts before I'm still not sure if that interface product is still activly supported by the SAP. Furthermore I have experienced certain curious effects that came up, e.g. that read-notifications from the last years have been sent once again. Also consider more network traffic etc.
    For the second scenario you where asking, you should think about opening a new thread and a bit of more detailed information about what you are asking exactly.
    Best wishes,
    Florin

  • Removing characters from an input data-field

    Hi.
    Is it possible to "Trim Off" characters from a Text Field data, and automatically input them into another Text field?
    Let's say I have the following code :
    *<Field name='telephonenumber'>*
    *<Display class='Text'>*
    *<Property name='title' value='Phone Number in International Format'/>*
    *<Display>*
    *</Field>*
    This code is to input the telephone number in International Format (such as :  +1 234 567 8900)
    Now, lets say that I want to create a second Data Text field for phone number; but, this time, it is for the phone number in LOCAL format.
    In other words, I want to write a code which will AUTOMATICALLY  remove the first 3 or 4 characters from the "International Number",  and input them into the "Local Number"  field.
    This would save me the trouble or writing the number a second time. My code should be able to simply Trim Off the initial "+1 234", and automatically input the remaining "*567 8900"* into the Local Number field.
    How could I accomplish this?
    Thanks

    Based on your code, it looks like you have fields called global.workgsmad (local style) and global.workgsm (international style)
    Assuming your global.workgsm format will always be '+x xxx xxx xxxx' you want to skip the first 6 characters, not 4
    The simplest way to do this is like so:
    <Field name='global.workgsmad'>
       <Expansion>
          <substr>
             <ref>global.workgsm</ref>
             <i>6</i>     <!-- Skip the country code and area code '+x xxx ' -->
             <i>8</i>   <!-- 8 characters were left for the format 'xxx xxxx' -->
          </substr>
       </Expansion>
    </Field>Alternatively, you could change the substr block to read
    <substr s='6' l='8'>
       <ref>global.workgsm</ref>
    </substr>Both formats are valid.
    If the phone number is not a fixed format, you'll have to do something more complicated.
    Jason

  • Problem when removing elements from table after apply sort

    Hi,
    I have big problem with <af:table> and sorting.
    When I removed objects from a table without sorting, there is no problem but when I removed
    items from the table after sorting, the remain items are not correct.
    For example, i have in my table these items :
    Item AA
    Item CC
    Item ZZ
    Item BB
    Item AA
    Item BB
    Item CC
    Item ZZ
    I sort the table and i select the following Items : Item BB a Item CC
    The remains item is only Item AA, Item ZZ disappear.
    If i resort the table, the missing Item zz appear again in the table.
    Here is my jspx :
    <af:table var="row" rowBandingInterval="1" width="1050" rows="5"
    rowSelection="multiple"
    value="#{pageFlowScope.editNotificationBackingBean.ingredients}"
    binding="#{pageFlowScope.editNotificationBackingBean.ingredientsTable}"
    autoHeightRows="10" id="t2">
    <af:clientListener method="goEditRow" type="dblClick"/>
    <af:serverListener type="doubleClickOnRow" method="#{pageFlowScope.editNotificationBackingBean.handleRequestIngredientsSelectBtn_action}"/>
    <af:column headerText="#{bundle.col_fr_name}" width="240"
    sortable="true" sortProperty="name.FR_Description" id="c1">
    <af:outputText value="#{row.name.texts['fr'].value}" id="ot1"/>
    </af:column>
    In my backing bean i call this method to remove selected elements :
    public void unselectBtn_action(ActionEvent actionEvent) {
    RowKeySet rowKeySet = selectIngredientsTable.getSelectedRowKeys();
    int i = 0;
    Iterator it = rowKeySet.iterator();
    while (it.hasNext()) {
         Integer index = (Integer)it.next() - i;
    selectIngredientsTable.setRowKey(index);
    CompositionIngredient compositionIngredient =
    (CompositionIngredient)selectIngredientsTable.getRowData();
    notification.getProductDetail().getCompositionIngredients().remove(compositionIngredient);
    i++;
    selectIngredientsTable.getSelectedRowKeys().clear();
    AdfFacesContext.getCurrentInstance().addPartialTarget(selectIngredientsTable);
    Thanks in advance.

    I have made a mistake, i don't paste the right <af:table> from my jspx.
    Here is the correct one :
    <af:table var="row" rowBandingInterval="1" width="1050"
    rowSelection="multiple" id="tableSelectedIngredients"
    value="#{pageFlowScope.editNotificationBackingBean.notification.productDetail.compositionIngredients}"
    binding="#{pageFlowScope.editNotificationBackingBean.selectIngredientsTable}"
    partialTriggers="::tab_ingredients_list_expressed_per">
    <af:column sortable="true" headerText="#{bundle.col_name}" id="c5" width="180"
    sortProperty="ingredient.name.FR_Description">
    <af:outputText value="#{row.ingredient.name.texts['fr'].value}"
    id="ot18"/>
    </af:column>
    ...

  • Strip Characters from String?

    Hi,
    How can I strip off some characters from the end of a string?
    I am not very good at regular expressions but perhaps I may not
    need one? Here is the data
    first_name_510
    last_name_2267
    I need a function that will strip off everything from the
    right including the underscore. I should be left with the below:
    first_name
    last_name
    Any help highly appreciated
    Regards

    if it is always an underscore, and always the last one, this
    should do
    the trick:
    #left(string, len(string)-len(listlast(string, "_"))-1)#
    string is assumed to be the variable holding your text
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/

  • Extract 2 characters from string

    Hello,
    Can anyone help to create a formula to extract 2 characters from the left of "pp" in a field using CR XI?
    Field = {MainEstimateDetails.JobDescription} (string)
    Sample string details:
    "Annual Report 96pp & Cover 12345"  - want to be able to show only 96 (from 96pp)
    "CTP A4 4pp" - want to be able to show only 4 (from 4pp)
    The string length is variable and the "pp" will be in different places each time.
    It is probably very simple, but I cannot get it

    Hi, 
    You can use the InStr function for this.  InStr returns the position of the string your are looking for. 
    NumberVar myPosition;
    If InStr ({MainEstimateDetails.JobDescription}, "pp") > 0 Then
        myPosition := InStr ({MainEstimateDetails.JobDescription}, "pp")
    Else myPosition := 0;
    If myPosition <> 0 Then
        {MainEstimateDetails.JobDescription} [(myPosition - 2) To (myPosition - 1)]
    Else "";
    This is a bit longer than I would normally do it but... I use Instr to check if the field has "pp" in it.  If it does it will return the character position in the field and I pass that to my variable myPosition. 
    If myPosition has a value then it parses out the two characters before "pp". 
    Good luck,
    Brian

  • Remove music from iPhone after enabling iCloud/match

    After enabling iCloud and iTunes Match, then after having some songs downloaded on my iPhone, I want to cycle some out and pull new ones down. However, I do not see how I can remove music from my iPhone. If I delete the playlist, the entire playlist is wiped from my master iTunes library, which removes it from all devices that use iCloud/Match.
    How do I selectively control what stays on my iPhone?
    Thanks,
    Derek

    If that is on, I highly recommend looking at th KB article: http://support.apple.com/kb/TS4054
    Specifically:
    Make sure iTunes Match is turned on.
    Please see this article for information about turning on or adding a computer or device to iTunes Match.
    If iTunes Match is already enabled on your computer or device, try turning iTunes Match off and then on again.
    On your Computer choose Store > Turn Off iTunes Match, then Store > Turn On iTunes Match.
    On your iOS device tap Settings > Music > iTunes Match Off, then Settings > Music > iTunes Match On.
    And sadly, you apparently can delete a song from Match from your phone.
    I am sorry, but no, you can't. If that were true, you would no longer see the song in your music library on your computer, and it would most likely be gone forever. The only way to remove an item from iTunes Match:
    To delete an item from iCloud in iTunes
    From a computer with iTunes Match enabled, open iTunes 10.5.1 or later on your computer. You can download the latest version of iTunes here.
    Click Music on the left side of iTunes.
    Select the item you would like to delete. Right-click the item and then choose Delete.
    You will be asked to confirm this action.
    If the item you want to delete exists in iTunes on your computer as well as in iCloud, click the checkbox to also delete the item from iCloud.
    Match is a train wreck. They need to make it work simply and intuitively.
    I don't disagree with you on this.

  • Batch job creating PO's from PR after a certain  date in PR

    Hello,
    We need to create PO from PR based on  certain number of days (4 days )  from the delivery date in PR. That is if delivery date in PR=30.4.14, then the PO should be created on 26.4.14 by the batch job (30.4.14 less 4 days ).
    How to achieve the above !
    regards
    Pamela

    Hello ,
    Please  find  the  links
    PR converted to PO batch job
    Background Batch job for PR & PO

Maybe you are looking for

  • How can I export my iTunes lib ray to an SD card

    I'm trying to export songs from library to an SD Card in my VW CC. Is there a good way to do so other than selecting the folders in the finder? Thanks,

  • ITunes Library (Damaged)

    Hey guys, using windows i got a blue screen error. booted my PC back up and opened iTunes. a small window come up about the library. i ignored it as i thought it'd say 'Find the directory' or something, but it just went i had no songs in my library.

  • Newbie : HD / SD / footage length

    Hello I have finish the editing of the film of the wedding of my daughter. This film was made with 4 cameras. 1 camera is in 1920 x 1080 29,97 fps 3 cameras are in 1440 x 1080 25 fps All my sequences are 1920 x 1080 25 fps or 29,97 fps Now I want to

  • Asynchronous/sync mdn

    Hello, I am able to post a file to AS2 server and see messages in Seeburger monitor. How do i configure the MDN for this scenario. What is difference b/w Asynch and Synch MDN . I just need to see MDN in the XI system. Please advice how this can be ac

  • CC 2014 constantly crashing

    CC 2014 has been crashing constantly for the past few weeks and has got worse since the last update. It is at the point now where it is un-usable, I have spoken to multiple support staff and nothing is being done. I have spoken to numerous other peop