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.

Similar Messages

  • Urgent pl.  I want to extract float from string (%f %s) or (%s %f) separate

    I want to extract float from string (%f %s) or (%s %f) separated by tab, whitespace etc., Since I am using jdk1.3.1 I can't use regular expression can anybody suggest a simple (one or two or few line code - compact) to get the float in (sign+/-)#.#### format ignoring other characters ?
    I tried:
    e.g.,
    String d="4.000 [tab]4";
    source string resulted from "SUBSTRING query of mySQL" can be of :
    " -4.543 XYZ ",
    " XYZ -4.546 ",
    " xx-yy 6.58 3 ",
    "6.0 xxx yyy zzz",
    the expected results for float from the string should be:
    -4.543
    -4.546
    6.580
    6.000
    If String containing data separated by comma:
    e.g.,
    "4.120     1     ,
    AAXXFE     ,4.206     1     ,
         4.000     1,
         4.201     1,
         4.189     1,
         4.204     1,
    S     DDERSF-RSA"
    The result should be: "4.120,4.206,4.000,4.201,4.189,4.204,0.000"
    The string is created by:
    ResultSet rs1 = stmt.executeQuery(S1);
    while (rs1.next()) {  
    String d = rs1.getString("SUBSTRING(FIELD1,LOCATE(\""+s2[i]+"\",FIELD1)+"+ k_st + ","+ length+")");
    System.out.print(d+",");
    May be I don't know how to use the following:
    float f1 = Float.parseFloat(d);
    ===
    String pattern = "###.###";
    //float value = -2100.578f;
    DecimalFormat myFormatter = new DecimalFormat(pattern);
    String output = myFormatter.format(d);
    System.out.println(d+" " + pattern + " " + output);
    ===

    Hi
    You made the best choice. JRegex is closer to java.util.regex.* and fine works with excellent performance in any JVM version so you can use examples/tutorials from both JRegex and Java.Sun.Com to learn more about regular expression.
    About the regular expression in my last post, there are two capturing groups: the first for float numbers in IEEE format specification (also see Java Language Specification) and the second for any sequence of chars, groups using with any amount of blank spaces (spaces, tabs, etc :: see regular expression definition) as delimiter. The anchors "^" and "$" are being used to exactly match pattern in target string and you can relax this constraint as needed.
    How to use JRegex? no secrets!
    import jregex.*;
    // a float number and string with any blank delimiter
    String patternString ="^([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?)\s+(.*)$";
    Pattern pattern = new Pattern(patternString); // different from Sun regex package syntax
    // below is identical in both packages
    Matcher m = pattern.matcher(anyTargetString);
    if (m.matches()) {
      Double d = Double.parseDouble( m.group(1) );
      String scratch = m.group(2);
      // your stuff goes here
    ..Remember to put JRegex jarfile in classpath!
    Regards and Success.

  • 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

  • More efficient way to extract number from string

    Hello guys,
    I am using this Regexp to extract numbers from a string, and I doubt that there is a more efficient way to get this done:
    SELECT  regexp_replace (regexp_replace ( REGEXp_REPLACE ('  !@#$%^&*()_+= '' + 00 SDFKA 324 000 8702 234 |  " ' , '[[:punct:]]',''), '[[:space:]]',''), '[[:alpha:]]','')  FROM dual
    {code}
    Is there a more efficient way to get this done ?
    Regards,
    Fateh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Or, with less writing, using Perl syntax \D (non-digit):
    SELECT  regexp_replace('  !@#$%^&*()_+= '' + 00 SDFKA 324 000 8702 234 |  " ','\D')
      FROM  dual
    REGEXP_REPLACE(
    003240008702234
    SQL>
    {code}
    SY.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • 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 date from string in T-SQL

    Hi,
    I am having one field(AT_TEXT) in my database that has below kind of values. I want to extract date from this string but the issue is all rows has different format.
    1)One Month Lttr sent on 3/12/2009 due to
    2)One Month Letter sent on 1/15/2009 due to
    3)One Month letter sent on7/15/2011.The amount due             - This has no space between on and 7 and . after yr
    4)One Month letter sent on 7/16/12 due to        - This has 12 instead of 2012(2 positions after 2nd slash/)
    Can anyone please help me to write query to extract date from this string?
    Vicky

    Hi Jingyang
    Li,
    I checked your query and it looks good but I have one issue. So when we reverse it, it looks like below and it is talking that $57.80 as a 1st numeric value and try to convert it into date and giving me error.
    I realize from your query that you are trying to reverse the value and then try to find out 1st Numeric value from that string, but my whole string has another numeric value at the end, like 
    "One Month Letter on 1/15/2009 due to non-pmt of prems-amt to avoid DE is $57.80"
    So when we reverse it, it looks like below and it is taking that $57.80 as a 1st numeric value and try to convert it into date and giving me error.         
    "08.75$ si ED diova ot eud tma - smerp fo tmp-non ot eud 9002/51/1 no retteL htnoM enO"
    Also sometimes I have $ amount at the end and sometimes I don't have any $ amount at the end, like below,
    "One Month letter sent on 10/15/2012 due to non-payment of premiums. The amount due to avoid dise"
    Can you please modify your query which takes only date part not the $ amount and give me?
    Thank you so much for your help 
    Vicky

  • Hyperion Brio: Computed Item Extract Number From String

    I would like to extract a number from a string in a computer item.  For example if I had a string such as "The customer purchased $5.00 of footballs", I would like to remove only the 5.00 from the string.  I would have to use the java functions in the results.  Any suggestions on how to do this?

    you can do this in the Results section with a computed column using the native string functions.  to break it down i have split it up a bit.
    strval is you string "The customer purchased $5.00 of footballs"
    position of $ = 25
         Instr ( strval, '$', 1, 1 )
    the starting position of the amount would then be 26
         Instr ( strval, '$', 1, 1 ) + 1
    position of decimal after $ = 26
         Instr ( strval, '.', Instr ( strval, '$', 1, 1 ), 1 )
    using Substr function you need to pick the string, the start value and the number of characters.
    string
         = strval
    start position
         = Instr ( strval, '$', 1, 1 ) + 1
    number of characters - location of decimal minus the start position plus 3 to get the cents
         = Instr ( strval, '.', Instr ( strval, '$', 1, 1 ), 1 ) - Instr ( strval, '$', 1, 1 )  + 3
    put all together
    Substr( strval, Instr ( strval, '$', 1, 1 ) + 1,  Instr ( strval, '.', Instr ( strval, '$', 1, 1 ), 1 ) - Instr ( strval, '$', 1, 1 )  + 3 ) * 1
    the multiply by 1 converts the string to number

  • Extract Number from string

    I need to extract the number, if it exists, from an alphanumeric text string.  I am told that the first two characters will be alpha and the remaining character(s) will be numeric, if the numeric exists at all.
    I know this is a simple formula, but I can't quite get it.

    Are the two alpha and remaining numeric characters always in the same position within the string?
    Are the two alpha characters always going to be the same?
    Is the length of the numeric value following the two alpha characters always going to be the same?
    The more no answers you have to the above the tougher it will be!
    Get back with the above answers and possibly copy and paste some examples of the ENTIRE strings from which you will be extracting the values and let us know which are the values you'll be pulling from within the larger string.
    "I need to extract the number, if it exists, from an alphanumeric text string. I am told that the first two characters will be alpha and the remaining character(s) will be numeric, if the numeric exists at all.
    I know this is a simple formula, but I can't quite get it."

  • Need a way to extract substring from string in oracle

    Hi all,
    I have one requirement related to extracting string from a paramater.
    suppose the string may like this in various format
    string:= 'This my string <Rid//problem/123456>'
    or
    string:= '<Rid//problem/123456> This my string'
    or
    string:= ' This is <Rid//problem/123456> my string'
    Now my requirement is i need to extract 123456 using pl/sql block.
    is there any way in oracle to get this thing done.
    Thanks n regards
    Laxman

    Hi,
    What version of Oracle ?
    How do you delimit the string to extract ?
    - always between the last / and before the >
    - the last string mande of number ?
    - the first string made of number ?
    Here are 3 possible answers :SQL> with s as (
      2  select 'This my string <Rid//problem/123456>' s from dual
      3  union all select '<Rid//problem/123456> This my string' from dual
      4  union all select ' This is <Rid//problem/123456> my string' from dual
      5  )
      6  select s.s,
      7  regexp_replace(s,'^.*/([0-9]*).*$','\1') r1,
      8  regexp_replace(s,'^[^0-9]*(.*?)[^0-9]*$','\1') r2,
      9  regexp_replace(s,'^.*/(.*?)>.*$','\1') r3
    10  from s ;
    S                                        R1       R2       R3
    This my string <Rid//problem/123456>     123456   123456   123456
    <Rid//problem/123456> This my string     123456   123456   123456
    This is <Rid//problem/123456> my string 123456   123456   123456If you're on 10g or more...
    Of course it also works in PL/SQL :SQL> l
      1  declare
      2  r1 varchar2(50) := 'This my string <Rid//problem/123456>';
      3  r2 varchar2(50) := '<Rid//problem/123456> This my string';
      4  r3 varchar2(50) := ' This is <Rid//problem/123456> my string';
      5  r1b varchar2(50);
      6  r2b varchar2(50);
      7  r3b varchar2(50);
      8  begin
      9  r1b := regexp_replace(r1,'^.*/([0-9]*).*$','\1') ;
    10  r2b := regexp_replace(r2,'^[^0-9]*(.*?)[^0-9]*$','\1') ;
    11  r3b := regexp_replace(r3,'^.*/(.*?)>.*$','\1') ;
    12  dbms_output.put_line('1 : '||r1||' -> '||r1b);
    13  dbms_output.put_line('2 : '||r2||' -> '||r2b);
    14  dbms_output.put_line('3 : '||r3||' -> '||r3b);
    15* end;
    SQL> /
    1 : This my string <Rid//problem/123456> -> 123456
    2 : <Rid//problem/123456> This my string -> 123456
    3 :  This is <Rid//problem/123456> my string -> 123456
    PL/SQL procedure successfully completed.Edited by: Nicosa on Jul 23, 2010 3:22 PM

  • How to extract substring from string... how to find the index?

    suppose i have a string like
    "string1 string2 string3 string4 string....stringK...stringN"
    i would like to extract the substring from string4 to stringK-1
    where stringK and string3 are pre defined strings (ie, i know exactly what stringK and string3 is).
    is there a function to extract the substring from string4 to stringK-1
    or is there a function i can use to determine the index of the end of string4 and the start of stringK?
    thks!

    If your substrings are seperated by a space (or by any other character that isn't used in any of the substrings), you could use something like StringTokenizer.
    If you wanna get real fancy, use the split method of String.

  • Extracting data from string

    Can anyone point me in the right direction as to how URL's
    can be extracted from a string?
    Or at least find the start and end positions...
    EG:
    I want to get the URL's from the "a href"'s...
    String- "The quick brown fox jumps over the lazy dog, <a
    href="
    http://www.example1.com">click
    here</a>. The quick brown fox jumps over the lazy dog, <a
    href="
    http://www.example2.com">click
    here</a>.".

    Hi,
    You can do this by using the "anchors" object in
    "Javascript".. Below is the Sample Code..
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
    Transitional//EN" "
    http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="
    http://www.w3.org/1999/xhtml">
    <head>
    <script language="javascript">
    function fnCheckAnchors()
    for (var i=0;i<document.anchors.length;i++)
    alert(document.anchors.item(i));
    </script>
    <meta http-equiv="Content-Type" content="text/html;
    charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <form name="form" action="" method="post"
    onsubmit="fnCheckAnchors();">
    <a name="1" href="
    http://www.yahoo.com">Yahoo</a><br
    />
    <a name="2" href="
    http://www.google.com">Google</a><br
    />
    <a name="3" href="
    http://www.altavista.com">Altavista</a><br
    />
    <input type="submit" name="submit" value="Submit" />
    </form>
    </body>
    </html>

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

  • Extract substring from string

    Hi,
    Iu2019m reaching out to the experts in the forum for assistance with resolving a code issue in Universe Designer u2013 itu2019s not producing the expected result.  The following are details, and steps taken:
    Objective: To extract only the characters between #u2019s, i.e. u2013 Smith, John added comments on 12/1/11 V5M#0.25# this is a test.  *NOTE* The characters before AND after the #u2019s varies.
    Database u2013 Oracle 10g
    Field type u2013 CLOB (DBAu2019s will not change) u2013 I created an object u201CDescriptionu201D= DBMS_LOB.SUBSTR("Oracle_Test_Unv". DESC, 4000,1) u2013 I also tried casting as a varchar2 and still the same result.
    Object u2013 Code to extract the characters between #u2019s:
         CASE WHEN @Select(Oracle_Test_Unv\Description) LIKE '%V5M#%#%'
                             THEN DBMS_LOB.SUBSTR(@Select(Oracle_Test_Unv\Description),
                                    DBMS_LOB.INSTR(@Select(Oracle_Test_Unv\Description), '#',1,1)+1,
                                          DBMS_LOB.INSTR(@Select(Oracle_Test_Unv\Description), '#',1,2) -
                                               DBMS_LOB.INSTR(@Select(Oracle_Test_Unv\Description), '#',1,1)-1)
                                                    ELSE '0'
                                                          END
    Current Result:  Smith, John added comments on 12/1/11 V5M#0.25
    Thanks in advance for your help!

    Apologies, I forgot to include the expected result.  Please see below:
    Expected result: 0.25
    Thanks again!

Maybe you are looking for

  • How do I run parallels in the guest account

    I recently updated my Mac Mini.  On the old one I was running Parallels, and had the guest account set up to be able to run parallels just fine.  I used Migration Assistant to transfer everything to the new Mac.  Unfortunately, now my guest account c

  • Images on website's are blurry,as are pictures that i upload to internet

    image's on website's are distorted,also picture's that i upload to facebook are distorted,but are crystal clear before i upload them.just image's are distorted on web page's not header's. i am wandering if i have a virus or is there some adjustment t

  • Lost reference to some pics

    iphoto seems to have lost a reference to some images. When I do a search for an image in the finder , the finder result says the photo is in a folder in the iPhoto library. iPhoto cant see just some of the files. I cant share this iPhoto library from

  • Select in random order?

    Is there any way to do a SELECT from a table/view, and tell it to randomize the order the rows are returned in? TIA -

  • WEIRD MacPro softRAID problem HELP

    MacPro RAID 0 problem I NEED HELP I am having a weird RAID problem with our new MacPro 2.66, MacOS 10.4.8, 5GB RAM, 4 x 500GB RAID 0, 1.8 TB in internal bays configuration, drives have been formatted individually, and the RAID 0 have been created wit