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/

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

  • 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

  • Removing unicode control characters from string

    Hi.
    I have a webservice where I return an object (with some strings) back to the client. The information is read from a database, and the string can sometimes contain invalid xml characters (like unicode 0x13). This results in an error when parsing the information at the client side.
    Is there someway a easy way to set up a filter or something that checks whether the string contains characters outside the valid range specified for XML's (lower than unicode 0x20 etc), and removes them/replace them with a different character?

    If you have to get rid of the control chars then       String someText = "a\nb\nc\td\re\r\nf";
            String someTextWithoutControlChars = someText.replaceAll( "[\u0000-\u0020]","");
            System.out.println(someTextWithoutControlChars);but like kaj says, some control chars are valid.

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

  • 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

  • Retreiving number and characters from string

    Hello fellow developers,
    Lets say i have the following string ER686 and want to split the string into a number and characterpart resulting in a String "ER" and an int "686". What is the best approach to accomplish this?
    Thank you for any help offered.

    The format is that there's a sequence of strings 2 or
    3 and a squence of numbers 3 or 4You might use a Pattern matcher, using a regular expression like the following :"(\\D{2,3})(\\d{3,4})"This expressions represents "two or three non-digit characters followed by 3 or 4 digits". The parenthesis are here to allow getting the two elements (groups) separately.
    Use the find() method of the matcher, then retrieve the two groups with group(1) and group(2).
    Eventually, parse the latter if required.

  • Extract Characters from String

    Hi
    Can anyone let me know how can i extract the letters HIJK from the following string
    Sting s = "ABCDEFGHIJKLMNOP"
    Thanks

    Thanks for that
    but if i do something like this it falls over
    String temp = s.substring(12, 3);You posted this response 2 minutes after the previous response. This means you obviously didn't take the time to read the String API to find out more information about the parameters for the method. Take some time to learn about new methods before claiming they don't work.

  • Removing last 2 characters from string field

    I am trying to remove the last 2 characters of a string field.
    there is no consistant length in the field
    316R1
    12364R1
    i want to remove everything after R
    i tried instrrev but i that didnt do it.
    is there a way to say
    start position1 and go the R
    thanks

    formula,
    left (field, length_formula) is the solution
    the length_formula is the number of chars form left
    f.i
    left(field, length (field)-2)
    left (field, InstrRev, field,"R")
    of course a combination with Right is also possible

  • Capturing characters from string

    Hey guys, I need a little bit of help. Thanks in advance!
    I have a user text input and I'm trying to save only the numbers in that string into a variable.
    For example: User enters "J123JS"
    var userNum=123
    How can I do so?
    Also, I'd like to check if a certain character is not a number or specified character then reneder an Error message to Output text.
    So far I have:
    var ch1=textbox.charAt(0);
    var ch2=textbox.charAt(1);
    var ch3=textbox.charAt(2);
    var ch4=textbox.charAt(3);
    if (ch1== /[^NWSE]/){ txtOutput.text="Error!!"; < This does nothing in my program. Renders no erros, yet does nothing!\
    I also tried:
    if (ch1== /[ABCDFGHIJKLMOPQRTUVWXYZ]/){ txtOutput.text="Error!!"; }
    still, nothing!
    Also, I'm trying to say if the 3rd character is not a number then render an error message
    I've tried:
    if (ch3!=/[0-9]/){
    txtOutput.text="Error!";
    No luck.
    Please help, thanks.

    To just extract numbers:
    var userNum:Number = Number(textbox.text.match(/\d/g).join(""));
    To check if there are number at all:
    if(!/\d/g.test(textbox.text)){
         txtOutput.text="Error!";
    To check by position:
    if (!Number(textbox.text.match(/./g)[3])) {
         txtOutput.text="Error!";

  • Removing offending characters from string...

    Hello. I have some code that receives a csv file that is generated by an AS/400 - info about store orders, etc. However occasionally there is a character that causes an exception when I try to send the data into XML (prep for a web service call).
    So, I added some code to my process to check the individual bytes. It's a byte value of 28 that causes me problems. I sometimes find it where I am expecting an apostrophe. So for testing purposes I added a routine that replaces byte=28 with an apostrophe, and all is well.
    My question revolves around the fact that I don't have a great understanding of character encoding, etc. Essentially, what should I be doing? Should I be using different character encoding when reading the file (currently using ISO8859-1)? I don't have much control over the actual XML generation, so my hands are tied on that end. It just seems that the solution that I implemented is less-than-ideal. (Although searching through this forum, I did find it as a suggestion...)
    Any help is greatly appreciated.
    Chris

    So any thoughts on the question of how to get rid of it?
    Just iterate over all bytes as I am now? Or is there a better solution?I assume you are using something like a buffered reader to read in the CSV file contents. Does the ISO 8859-1 encoding have problems with the FS control code byte or does it simply read it in and decode it into \u0028 ? if the latter, my own inclination would be to handle it on the char level, (by replacement or removal) before you generate your XML. What you replace it with depends on its original function within the CSV file, which I don't know.
    Joe

  • Removing binary characters/ special chrs from string entered by user

    Dear gurus,
    I have a string entered by users in database from where i am pulling data into SAP BW.
    Th problem is that the string contains binary characters. It is showing error and cant be upoaded
    Is there any function module/ code that removes binary data an special chrs from string??
    Pls help. thanks.

    Hi,
    U can use the Tcode:  RSKC,
    to allow the special charecters...
    otherwise if u r sure that u r facing only that type of errors..then u can allow the
    errors in ERROR HANDLING tab present in the infopackage screen < Update tab
    bye,
    sunil4points

  • Removing non english characters from my string input source

    Guys,
    I have problem where I need to remove all non english (Latin) characters from a string, what should be the right API to do this?
    One I'm using right now is:
    s.replaceAll("[^\\x00-\\x7F]", "");//s is a string having chinese characters.
    I'm looking for a standard Solution for such problems, where we deal with multiple lingual characters.
    TIA
    Nitin

    Nitin_tiwari wrote:
    I have a string which has Chinese as well as Japanese characters, and I only want to remove only Chinese characters.
    What's the best way to go about it?Oh, I see!
    Well, the problem here is that Strings don't have any information on the language. What you can get out of a String (provided you have the necessary data from the Unicode standard) is the script that is used.
    A script can be used for multiple languages (for example English and German use mostly the same script, even if there are a few characters that are only used in German).
    A language can use multiple scripts (for example Japanese uses Kanji, Hiragana and Katakana).
    And if I remember correctly, then Japanese and Chinese texts share some characters on the Unicode plane (I might be wrong, 'though, since I speak/write neither of those languages).
    These two facts make these kinds of detections hard to do. In some cases they are easy (separating latin-script texts from anything else) in others it may be much tougher or even impossible (Chinese/Japanese).

  • Removing non-alpha-numeric characters from a string

    How can I remove all non-alpha-numeric characters from a string? (i.e. only alpha-numerics should remain in the string).

    Or even without a loop ?
    Extract from the help for the Search and Replace String function :
    Right-click the Search and Replace String function and select Regular Expression from the shortcut menu to configure the function for advanced regular expression searches and partial match substitution in the replacement string.
    Extract from the for the advanced search options :
    [a-zA-Z0-9] matches any lowercase or uppercase letter or any digit. You also can use a character class to match any character not in a given set by adding a caret (^) to the beginning of the class. For example [^a-zA-Z0-9] matches any character that is not a lowercase or uppercase letter and also not a digit.
    Message Edité par JB le 05-06-2008 01:49 PM
    Attachments:
    Example_VI_BD4.png ‏2 KB

  • Removing Non-Ascii Characters from a String

    Hi Everyone,
    I would like to remove all NON-ASCII characters from a large string. For example, I am taking text from websites and would like to remove all the strange arabic and asian characters. How can I accomplish this?
    Thank you in advance.

    I would like to remove all NON-ASCII characters from a large string. I don't know if its a good method but try this:
    str="\u6789gj";
    output="";
    for(char c:str.toCharArray()){
         if((c&(char)0xff00)==0){
              output=output+c;
    System.out.println(output);
    all the strange arabic and asian characters.Don't call them so.... I am an Indian Muslim ;-) ....
    Thanks!

Maybe you are looking for