Removing characters

I need some help on removing characters from a string. The problem I am having is due to the fact the portion of the string I need to keep varies. A few examples are:
1298-1011-1-842-10-0
1298-1011-1-842-103-0
1298-1011-1-842-1034-0
1298-1011-1-842-10345-0
I need only the fifth set of numbers (10,103,1034,10345) out of these id numbers. I guess I need a way to remove everything with a "-" from both the right and left of the fifth set of numbers. The left function works to remove the trailing two digits ("-0") off of each string. I am just having a problem figuring out how to strip out the rest when it varies. Any help would be appreciated.

If you are using 10g you could use REGEXP_REPLACE. For example...
create table test1 (col1 varchar2(50));
insert into test1 values ('1298-1011-1-842-10-0');
insert into test1 values ('1298-1011-1-842-103-0');
insert into test1 values ('1298-1011-1-842-1034-0');
insert into test1 values ('1298-1011-1-842-10345-0');
create table test2 (c1 number, c2 varchar2(10));
insert into test2 values (10, 'a');
insert into test2 values (103, 'b');
insert into test2 values (1034, 'c');
insert into test2 values (10345, 'd');
SQL> select regexp_replace(col1, '.*-.*-.*-.*-(.*)-.*', '\1') col5 from test1;
COL5
10
103
1034
10345
SQL> select t1.*, t2.* from test1 t1, test2 t2
  2  where regexp_replace(t1.col1, '.*-.*-.*-.*-(.*)-.*', '\1') = t2.c1;
COL1                                                       C1 C2
1298-1011-1-842-10-0                                       10 a
1298-1011-1-842-103-0                                     103 b
1298-1011-1-842-1034-0                                   1034 c
1298-1011-1-842-10345-0                                 10345 d
SQL> JR

Similar Messages

  • Remove characters in a string

    wondering.. anyone knows how to remove characters in a string
    e.g.
    string: applepie
    after removing last 3 chars become "apple"
    thanks...

    That of course will only work for this example. Better solution is to use indexOf() to locate the position of the string you wish to remove. If the string you wish to remove is in the middle, then you will have to do a bit of extra work and concat two substrings.

  • How to remove characters/lines from the beginning of an InputStream

    Hi,
    I have a program which receives several InputStreams. From each of these streams I have to remove 2 lines from the beginning. After the lines are removed, all the streams are combined to one with SequenceInputStream and read in one chunk. Is there an easy/simple way of doing this?
    One option I thought would be to read the char by char until 2 end of line chars have been detected and then read the rest of the data to a buffer. And the create a ByteArrayInputStream out of this buffer. Problem with this approach is, that the amount of data can be large, so putting all the data in to memory might cause problems.
    Another option is to use BufferredInputStream and use the readline() method twice to get rid of the lines that are not needed. After this I would write the data to some output stream, which is then converted back to input stream. Propably would work, but sound too much of work for a simple thing like this. There has to be better way.
    To make it simple, what I need is a method that looks like the following, or something similar
    *  Removes n number of lines from the beginning of a InputStream.
    *  @param is InputStream where the lines are removed
    *  @param numberOfLines int value to indicate how many lines whould be removed
    *  @return InputStream where lines have been removed.
    public InputStream removeLines(InputStream is, numberOfLines);Thanks.

    Here's the code, feel free to use it. Comments are also welcome.
    public InputStream removeLinesFromTheBeginning(InputStream is, int numberOfLines) throws IOException
              char c = 'c';
              int i = 0;
              for(int n = 0 ; n < numberOfLines ; n++)
                   do
                        c = (char)is.read();
                        System.out.print(c);
                        if(c == (char)-1)     // end of stream reached before any newline characters were found.
                             return null;
                        i++;
                   while(c != '\n');
                   System.out.println();
                   System.out.println("Characters removed:" + i);
                   System.out.println("n: " + n);
                   i = 0;
              return is;
         }Edited by: dave_spaghetti on Jun 16, 2009 5:42 AM
    Fixed a bug.

  • 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

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

  • Removing characters from a String

    Hi!
    I have a large String that has some unwanted characters in it that I want to remove. Here is an example:
    AA1lbmNvZGVkUGFy\015\012YW1zdAACW0JbABBlbm5MQ2Is there any method I can use to remove the characters \015\012 from the String. I looked at the method String.replace(char, char); but this is unsuitable because I can only remove one charater at a time an I may have this character occuring legitimately elsewhere in my String. Would it be possible in some way to traverse the String and identify the pattern of \015\012 and remove that.
    I'd appreciate any help,
    Thanks
    Chris

    Specifically,  str = str.replaceAll("\\\\01[25]", "");The replaceAll method is only available in v1.4.0 or later.

  • APEX 2.2.1 removing characters in html rendering??

    Hi, I am developping on APEX 2.2.1 because our client is running that version. Now here is one strange issue : with FireFox 2,3 or IE 6,7 when I run a certain page some characters in the javascript that was in my HTML HEADER are removed, so it creates a javascript error. This is very strange, when I go in edition for example, i will see this code:
    myFunction('p1','p2','p3');
    But when I run it, and I look at the page source I will see:
    myFunction('p1''p2','p3');
    In this case, it was the comma, but some times it's a couple of characters. I thought maybe it was a certain overflow, but I had less than 4000 characters in my html header.
    Also, I had a similar thing with a process. I created a process and it compiled fine. When I ran the page everything was working, but when I went to edit the process, some characters were missing, so obviously when I applied the changes there was an error.
    Now, I don't know if it's a database problem or an APEX problem. My db is 10G release 2 and my APEX version is : 2.2.1.00.04. Maybe there is some patch missing I don,t know, but I hope some of you came across something similar. Thanks
    Reginald

    By looking at the questions I asked in my profile, I noticed that I didn't give any follow up to this one. Well, I don't have the problem anymore. All I know is that my dba applied a patch and it fixed the problem. Thanks for your time.

  • Remove characters

    I need to remove some characters from the start of a string
    in order to get the ID I need when referencing the database.
    The string passed is as follows.
    Three letter country code and then the id is always presented
    as 7 digits - I need to remove the code and any preceeding zeros
    EG
    GBR00456341 needs to be 456341 etc etc.
    I tried using replace but it doesn't seem to work for all the
    preceeding zeros.
    HELP!

    try regular expressions. something like:
    #REReplaceNoCase(yourstring, "([A-Z]{1,3}0+)(\d+)", "\2")#
    will do what you want.
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com

  • Remove characters from rightside

    In my query I select the following table
    ,pa_expenditure_items_all.ORIG_TRANSACTION_REFERENCE.
    The output gives values like
    12567245:2
    12567244:2
    12567247:3
    9367349:2
    9367349:4
    I would like to remove the last two positions in this output.
    However this proves to be, for me, more difficult then expected.
    The total number of characters varies so i can't use SUBSTR with counting starting from the left side.
    I tried REPLACE and TRIM but didn't get it right.
    Hope someone can help my out on this.

    Several methods are available:
    WITH pa_expenditure_items_all AS (SELECT '12567245:2' orig_transaction_reference
                                        FROM dual
                                       UNION
                                      SELECT '9367349:23'
                                        FROM dual
                                       UNION
                                      SELECT '79367349'
                                        FROM dual
    SELECT orig_transaction_reference
         , SUBSTR(orig_transaction_reference
                 ,1
                 ,DECODE(INSTR(orig_transaction_reference, ':')
                        ,0, LENGTH(orig_transaction_reference) + 1
                        ,INSTR(orig_transaction_reference, ':')
                        ) - 1
                 ) new_val_v1
         , REGEXP_SUBSTR(orig_transaction_reference
                        ,'^[^:]+'
                        ) new_val_v2            
      FROM pa_expenditure_items_all
    ORIG_TRANS NEW_VAL_V1 NEW_VAL_V2
    12567245:2 12567245   12567245
    79367349   79367349   79367349
    9367349:23 9367349    9367349C.

  • Remove Characters from a Date

    What are some ways that I could remove the hyphens, semicolons, periods, and empty strings from a date (in a single expression)?
    If I have a date (returned from GETDATE()) as follows:
    2014-09-15 16:53:09.253
    I want to remove the non-numeric characters and return this:
    20140915165309253
    Can REPLACE be used to identify more than one character pattern to replace?
    Thank you for your help!
    cdun2

    Another way, don't remove at all, begin with just the requisite dateparts and datenames. Although either way works fine, this way gives you absolute control over how you render.
    In this example, the "from sys.messages" is not part of the answer, I just included it to recreate a test to compare speeds.  It ends up having the same speed/execution plan/actual CPU time used either way. 
    The "Right()" functions are required, because for example, if the time is 8:03, the "03" is presented as just "3", so you have to force it to render as "03" with the Right function.  The DatePart(month) is the
    only one returning an integer result, so that must be cast as Varchar, the DateName() functions return a string, although unfortunately with leading zeroes removed.
    Select Datename(year, SysDateTime())
    + Right('0' + Cast(DatePart(month, SysDateTime()) as varchar(2)) , 2)
    + Right('0' + DateName(day, SysDateTime()), 2)
    + Right('0' + DateName(hour, SysDateTime()), 2)
    + Right('0' + DateName(minute, SysDateTime()), 2)
    + Right('0' + DateName(second, SysDateTime()), 2)
    + Right('0' + DateName(ms, SysDateTime()), 3) , sysdatetime()
    from sys.messages sm1
    Select REPLACE(REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(30), GETDATE(), 121),'-',''),':',''), '.',''),' ',''), sysdatetime()_
    from sys.messages sm1

  • FM to Remove Characters

    Hi Fellas ...
    I need a FM to remove all kind of characters in a char variable. See the example.
    DATA: lv_char TYPE char10 VALUE 'ABC123',
                lv_num  TYPE char 10.
      lv_num = lv_char+3(3).
    That is one possibility, however, I also can have:
    DATA: lv_char TYPE char10 VALUE 'A1B2C3',
                lv_num  TYPE char 10.
    How I can separate the lv_char to have the same 123 in variable lv_num ?
    I can have all kind of possibilities of numbers and characters scrambled.
    Thx.

    Hi,
    use SCP_REPLACE_STRANGE_CHARS or
    use FM SF_SPECIALCHAR_DELETE
    Import parameters Value
    WITH_SPECIALCHAR ASDASD@@#$ASDASD<
    Export parameters Value
    WITHOUT_SPECIALCHAR ASDASDASDASD
    or you can use the below statement.
    REPLACE ALL OCCURRENCES OF REGEX '[^[:alnum:]]' IN lv_text WITH ''.
    or here is another sample code.
    first cout the string lenght..
    DATA: w_string(255) TYPE c,
          w_str(255) type c,
          w_c1 TYPE i,
          w_c2 TYPE i,
          w_count TYPE i,
          w_sub_str TYPE c.
    CONSTANTS : c_str(22) VALUE '&*=!@#$%[]{}\^|;`"_~'.   "Prohibited Character still you ca add SPL characters
          w_count = STRLEN( w_str ).
    *   Clears the string
          CLEAR w_string.
          w_c2 = 0.
          DO w_count TIMES.
            w_sub_str = w_str+w_c1(1).
            IF w_sub_str CN c_str OR w_sub_str EQ space.
                w_string+w_c2(1) = w_sub_str.
                w_c2 = w_c2 + 1.
            ENDIF.
            w_c1 = w_c1 + 1.
          ENDDO.
          CLEAR: w_c1,  w_count.
          SHIFT w_string LEFT DELETING LEADING space.
    Edited by: Harini Gopinath on Oct 27, 2009 6:31 PM

  • Issue with variable, need to remove characters

    Hi Team,
    i have one problem regarding the variable.
    i have some variable for example 'MALT011000012345MTLCAST001SMT84'.
    in the above variable i need to replace the value of M with say 5, value of A with 9 and so on .
    like i want to repalce each character with number field.
    can you please share your ideas that how can i resolve this issue in PL/SQL?

    Hi,
    Here's one way:
    str := TRANSLATE ( str
                     , 'MA'
                     , '59'
                     );where str is any string, such as 'MALT011000012345MTLCAST001SMT84'.
    The 2nd and 3rd arguments to TRANSLATE can be any length (1 or more); I just included the 2 character pairs that you mentioned. The n-th character of the 2nd argument will be replaced with the n-th character of the 3rd argument.
    I hope this answers your question.
    If not, please post a little sample data (that is, strings that contain 'M''s, 'A's, and/or the other characters you need to replace) and what you want all those strings turned into. Post the sample data as CREATE TABLE and INSERT statements so we can test them all in one query.

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

  • Remove characters from phonenumbers

    Hello,
    I have the following problem:
    35% of the phonenumbers in my contacts contain a wrong phone number format.
    Some phonenumbers in my contacts contain a format like +<country code> (0)<area code> phonenumber  or (+<country code> <area code>)<phonenumber> or (<areacode>)<phone number>
    Because the numbers are formated with ( ) and - i have problems with my bluetooth device when dailing from my addresbook/contacts
    I want to remove the (0) from all the phone numbers and all other illegal charactars so the format will be like this:
    +<country code> <areacode> <phonenumber>
    I tried the Mac App Contacts Cleaner but this app does not reconize the current format and can not translate to my required format.
    So i have to edit 200 contacts by hand.
    Please advice.
    Thanks

    Try this:
    $iscsitarget = Get-EqlVolume -VolumeName TZ | select -ExpandProperty iSCSITargetName

Maybe you are looking for

  • How can I create a bootable DISK IMAGE of my PB Internal Drive?

    I would like to make a bootable image of my Hard Drive but without including any Free Space. You see all I need on the image are the OSX and the programs, NOT the 60GB of Free Space. Disk Utility however wants to create a 80gb image which includes 60

  • Setting up of Transports Management System  in EP7.0

    Hi Experts!!!!! Can you please provide the documents or links for configuring the transport management system for EP 7.0 Systems. Regards, Vamshi.

  • Outlook from Office 2011 can't start after OS X Security Update 2014-005

    I just installed Security Update 2014-005 on OS X v10.9.5 in a MacBook Pro (2012). After the OS restarts, Microsoft Outlook from Office 2011 fails to start. Did anyone else experience this issue and have a solution that can be shared?

  • Manage btrfs snapshots

    One of the feature that i much like about btrfs is Snapshot. What i want to do is to create snapshots of /home every 5/15 minutes (i have to test better the impact on performance) and retain: 02 - Yearly snapshots 12 - Monthly snapshots 16 - Weekly s

  • How can I export and import a score in flash?

    I run a "Classic Game Show" night at a bar, and have created scoreboards in flash for games like the Family Feud, Wheel of Fortune, and others. Each team gets to compete in a few different games. This is all computer based, not on the web (so no PHP