How to get specific character from a string

I have a value such as: 0-5 or 123-30. This is a combination
from 2 different IDs.
All I need is to get the number on the right (5 from 0-5 OR
30 from 123), any number on the right of the "-" character not
including
the "-"
I'm not sure what ColdFusion function can I use safely.
I said safely since all I can find is either Left or Right
functions. With these 2 functions, I need to specify the number of
character to extract while in my case the application is growing so
the ID may currently be only 1 digit each (0-5) but later it may
grow longer (123-5677).
If anyone know the function, please help me. Thank you!

Something like this?
Mid(string, Find("-",string)+1 ,
Len(string)-Find("-",string))
Since
Mid(string, start, count)
and
Len(string or binary object)
and
Find(substring, string [, start ])
Or perhaps ....
ListLast(string, "-")
since
ListLast(list [, delimiters ])
Phil

Similar Messages

  • How to get a char from a String Class?

    How to get a char from a String Class?

    Use charAt(int index), like this for example:
    String s = "Java";
    char c = s.charAt(2);
    System.out.println(c);

  • How to get each character in a string

    as in 'C' we use arrays to get each character of a string stored in array.how can we get each character of a string stored in a variable.

    Hi,
    For that you need to do offset.
    for example one variable called VAR contains string 'HUMERAH'.
    if you want each character of that string then you need to decalre as many variable as the number of string.
    like
    data : var1(1),
             var2(1),
    var(3),
    var(4).
    var1 = var+(1).
    var2 = var+1(1).
    var3 = var+2(1).
    var4 = var+3(1).
    now var1,var2,var3,var4. contains the single characters.
    Regards,
    Guru
    mark helpful answers

  • How to get a character from input stream withjout pressing RETURN key?

    In C, we could use getch() form <conio.h> to get a character from the input steam without pressing the return/enter key. How could I tranlate this function for use in Java?

    public static char readChar()
    int charAsInt = -1; //To keep the compiler happy
    try
    charAsInt = System.in.read();
    catch(IOException e)
    System.out.println(e.getMessage());
    System.out.println("Fatal error. Ending Program.");
    System.exit(0);
    return (char)charAsInt;
    }

  • How to extract specific line from a string

    Hi guys.
    I?m starting to work with java...
    i have the following data inside a string variable:
    0 rows inserted.
    0 rows updated.
    0 rows ignored.
    98 rows marked as deleted.
    0 rows have no country.
    3345 rows have no geo.
    0 rows are invalid.
    what i want to do i to extract the number of rows marked as delete.
    I think that i figured out how to extract the number from this line :"98 rows marked as deleted."
    but how do i get to that line?
    I hope you can Help me. Thanks.

    the string is the result from a Function... this function gets the info from a store procedure...
                   rta = "Results for " + dh.getSource() + " source:\n" +
    dh.getInsertedCount() + " rows inserted.\n" +
    dh.getUpdatedCount() + " rows updated.\n" +
    dh.getIgnoredCount() + " rows ignored.\n" +
                   dh.getDeletedCount() + " rows marked as deleted.\n" +
                   dh.getNoCtryCnt() + " rows have no country.\n" +
                   dh.getNoGeoCnt() + " rows have no geo.\n" +
                   dh.getInvalidCnt() + " rows are invalid.\n";
    i can?t change this function...
    so i need to work with the returned value...
    i what thinking to use the following method to extract te number...
    private int GetNumericValue(string sVal)
    int iFirst, iCharVal, iEnd;
    int iMult = 1, iRet = 0;
    char[] aNumbers = "1234567890".ToCharArray();
    iFirst = sVal.IndexOfAny(aNumbers);
    iEnd = sVal.LastIndexOfAny(aNumbers);
    if (iEnd < 0)
    return 0;
    string subStr = sVal.Substring(iFirst, iEnd - iFirst + 1);
    iEnd = subStr.Length - 1;
    while (subStr.Length > 0)
    iCharVal = int.Parse(subStr[subStr.Length-1].ToString());
    iRet += iMult * iCharVal;
    iMult *= 10;
    if (iEnd <= 0)
    break;
    subStr = subStr.Substring(0, subStr.Length - 1);
    iEnd = subStr.LastIndexOfAny(aNumbers);
    subStr = sVal.Substring(iFirst, iEnd + 1);
    return iRet;
    but i still need the 4rd line to extract the number

  • How to get specific rows from the vo or Iterator in the backing bean?

    Hi,
    I have to get the specific number of rows from iterator in the backing bean. means i want to get the records from the VO or Iterator only from 5 th record to 10th record its like rownum in SQL.
    We can use rownum in VO sql query. but there would be a performance issue with that ...
    SO i am trying to get the rows from ADF Iterator once we fetch from DB.
    Is it possible to do that ?
    Do we have any way to set the pointer to the VO/Iterator like setFirst() and after that setMaxResult to retrun the rows between first and maxresult..
    Thanks

    If this is for pagination, then af:table offers pagination by design when you set accessmode=RangePaging or RangePagingIncremental in VO. Paginated queries are fired when scroll down in the table. Explore this option before you try out any custom solution
    To answer the question,
    Note: same logic i have implpemented ADF with EJB ..In EJB Query class we have setFirst(int) and setMaxResult(int) methods...simply i did setFirst(30) and setMaxResult(10)..It worked fine...Theoretically speaking the same can be achieved by setting setRangeStart() on the viewobject(which in turn sets to the default rowset) and by setting max fetch size on VO + accessmode=RangePaging. However when you use table with ADF binding, these will be overridden by the binding layer. If you are not using ADF binding, then the above is same as what you did for JPA entity. Other option is, you build expert mode VO with rownum for this special case, which will work if you dont need to set accessmode=RangePaging for VO.

  • How to get numeric data from a string using t-sql

    Hi All,
    I have a table with 2 columns ID as Int and Message as nvarchar(max)
    Create table Sample
    ID int not null,
    Message nvarchar(max) null,
    CONSTRAINT [PK_ID_Msg] PRIMARY KEY CLUSTERED
    ID asc
    Insert statement:
    INSERT INTO
    Sample (ID, Message)
    VALUES (1, 'X_YRS: 00 ; X_MONS: 18 ; X_DAYS: 000 ; Y_YRS: 00 ; Y_MONS: 16 ; Y_DAYS: 011 ; Z: 1 ; Z_DATE: 09/04/2014
    INSERT INTO Sample (ID, Message) VALUES (2, 'X_YRS: 01 ; X_MONS: 15 ; X_DAYS: 010 ; Y_YRS: 00 ; Y_MONS: 18 ; Y_DAYS: 017
     ; Z: 1
     ; Z_DATE: 06/02/2012')
    Data in the table looks like:
    ID             Message
    1       X_YRS: 00 ; X_MONS: 18 ; X_DAYS: 000 ; Y_YRS: 00 ; Y_MONS: 16 ; Y_DAYS: 011 ; Z: 1 ; Z_DATE: 09/04/2014
    2       X_YRS: 01 ; X_MONS: 15 ; X_DAYS: 010 ; Y_YRS: 00 ; Y_MONS: 18 ; Y_DAYS: 017 ; Z: 1 ; Z_DATE: 06/02/2012
    Need out put as below, just with numeric data:
    ID      X-Column         Y-Column         
    1       00 18 000        00 16 011
    2       01 15 010        00 18 017
    So, please I need t-SQL to get above output.
    Thanks in advance.
    RH
    sql

    ;With CTE
    AS
    SELECT s.ID,RTRIM(LTRIM(STUFF(Val,1,CHARINDEX(':',Val),''))) AS Val,RTRIM(LTRIM(LEFT(Val,CHARINDEX('_',Val+'_')-1))) AS Pattern,
    --ROW_NUMBER() OVER (PARTITION BY LEFT(Val,CHARINDEX('_',Val+'_')-1) ORDER BY RTRIM(LTRIM(STUFF(Val,1,CHARINDEX(':',Val),'')))*1)
    f.ID AS Seq
    FROM Sample s
    CROSS APPLY dbo.ParseValues(s.[Message],';')f
    WHERE ISNUMERIC(RTRIM(LTRIM(STUFF(Val,1,CHARINDEX(':',Val),'')))+'0.0E0')=1
    SELECT ID,
    STUFF((SELECT ' ' + Val FROM CTE WHERE ID = c.ID AND Pattern = 'X' ORDER BY Seq FOR XML PATH('')),1,1,'') AS XCol,
    STUFF((SELECT ' ' + Val FROM CTE WHERE ID = c.ID AND Pattern = 'Y' ORDER BY Seq FOR XML PATH('')),1,1,'') AS YCol,
    STUFF((SELECT ' ' + Val FROM CTE WHERE ID = c.ID AND Pattern = 'Z' ORDER BY Seq FOR XML PATH('')),1,1,'') AS ZCol
    FROM (SELECT DISTINCT ID FROM CTE)c
    ParseValues can be found here
    http://visakhm.blogspot.in/2010/02/parsing-delimited-string.html
    Numeric check logic is as per below
    http://visakhm.blogspot.in/2014/03/checking-for-integer-or-decimal-values.html
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Get first character from a String

    Hi!
    I've got a problem with the login of my program:
    I want to get the first character out of a String to select two types of users.
    eg.
    login "a20202" --> a --> first kind of user or
    login "b20202" --> b --> second kind of user
    Can you please help me?
    Bye
    Liz

    Am I on way to challenge the Worst Code Awards 2004 ? Let me have a go ... It is a far superior code-generating version :)
    Kept to ascii-range for the benefit of your monitor (and eyes):class NoMyWayIsFarSuperior {
         public static void main(String[] args){
              System.out.println("public static char getFirstChar(String message){");
              for(int k = 0; k < 256; k++){
                   System.out.println("  if(message.charAt(0) == " + k + ") return '" + ( (char) k) + "';");
              System.out.println("  throw new Exception(\"First char not within ascii range ... Please try again.\"); ");
              System.out.println("}");
    } The potential for optimisation is endless! :)

  • How to extract specific text from a string using REGEXP

    Some- &3*1233 Test Oralce #1`2" pip, various lengths couplers Misc. Metal,,'VENDOR'), PART_NO=5966 DESCRIPTION=INV 564400 2"
    How can I extract text start from 'Test' and end before DESCRIPTION? the results I need is as follows:
    Test Oralce #1`2" pip, various lengths couplers Misc. Metal,,'VENDOR'), PART_NO=5966
    I will apprecaite if you could explain the solution.

    set define off
    with t as(
              select 'Some- &3*1233 Test Oralce #1`2" pip, various lengths couplers Misc. Metal,,''VENDOR''), PART_NO=5966 DESCRIPTION=INV 564400 2"' str from dual
    select  regexp_replace(str,'(^.*)(Test.*)( DESCRIPTION.*$)','\2') result
      from  t
    RESULT
    Test Oralce #1`2" pip, various lengths couplers Misc. Metal,,'VENDOR'), PART_NO=5966
    SQL>
    {code}
    SY.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to remove certain character from a string?

    Follows the table:
    CT_TRABALH
    400rj101
    400rj102
    400rj103
    400rj104
    400rj105
    400rj106
    400rj107
    400rj108
    400rj109
    400rj1010
    400rj1011
    I woulld like to make the following with its values. For example the value 400rj1010
    I would like to remove its last character (400rj101) and then relace the last zero for the last number(400rj111) by query. Is there any way I can achieve this?

    I would write something a little more generic :
    SCOTT@demo102> with tbl as
      2      (select '400rj101' as CT_TRABALH from dual union all
      3       select '400rj102' from dual union all
      4       select '400rj103' from dual union all
      5       select '400rj104' from dual union all
      6       select '400rj105' from dual union all
      7       select '400rj106' from dual union all
      8       select '400rj107' from dual union all
      9       select '400rj108' from dual union all
    10       select '400rj109' from dual union all
    11       select '400rj1010' from dual union all
    12       select '400rj10120' from dual union all
    13       select '400rj14120' from dual union all
    14       select '412rj14120' from dual union all
    15       select '400rj1011' from dual )
    16  select CT_TRABALH,
    17         case when substr(CT_TRABALH,-1,1) = '0'
    18              then  decode(instr(substr(CT_TRABALH,1,length(CT_TRABALH)-1),0,-1),
    19                           0, substr(CT_TRABALH,1,length(CT_TRABALH)-1),
    20                              substr(CT_TRABALH,1,instr(substr(CT_TRABALH,1,length(CT_TRABALH)-1),0,-1)-1)
    21                              ||substr(CT_TRABALH,-2,1)
    22                              ||substr(CT_TRABALH,instr(substr(CT_TRABALH,1,length(CT_TRABALH)-1),0,-1)+1,
    23                               length(CT_TRABALH)-instr(substr(CT_TRABALH,1,length(CT_TRABALH)-1),0,-1)-1))
    24              else CT_TRABALH
    25              end as CT_TRABALH_0
    26  from tbl;
    CT_TRABALH CT_TRABALH_0
    400rj101   400rj101
    400rj102   400rj102
    400rj103   400rj103
    400rj104   400rj104
    400rj105   400rj105
    400rj106   400rj106
    400rj107   400rj107
    400rj108   400rj108
    400rj109   400rj109
    400rj1010  400rj111
    400rj10120 400rj1212
    400rj14120 402rj1412
    412rj14120 412rj1412
    400rj1011  400rj1011
    14 rows selected.
    SCOTT@demo102> Nicolas.

  • How to get each value from a parameter passed like this '(25,23,35,1)'

    Hi
    One of the parameter passed to the function is
    FUNCTION f_main_facility(pi_flag_codes VARCHAR2) return gc_result_set AS
    pi_flag_codes will be passed a value in this way '(25,23,35,1)'
    How to get each value from the string
    like 25 first time
    23 second time
    35 third time
    1 fourth time
    I need to build a select query with each value as shown below:-
    (SELECT t2.org_id, t4.description
    from org_name t2, ref_org_name t3, code_table t4
    where t2.att_data = t4.code
    and t3.ref_code = t2.att_type
    and t2.att_type = 25 and t3.code_type = t4.code_type
    and to_date('01-JAN-10', 'DD-MON-YY') between t2.att_start_date AND t2.att_end_date) q1,
    (SELECT t2.org_id, t4.description
    from org_name t2, ref_org_name t3,code_table t4
    where t2.att_data = t4.code
    and t3.ref_code = t2.att_type
    and t2.att_type = 23 and t3.code_type = t4.code_type
    and to_date('01-JAN-10', 'DD-MON-YY') between t2.att_start_date AND t2.att_end_date) q2,
    (SELECT t2.org_id, RTRIM(xmlagg(xmlelement(e, t4.description || ';')
    ORDER BY t4.description).EXTRACT('//text()'), ';') AS DESCRIPTION
    from org_name t2, ref_org_name t3,code_table t4
    where t2.att_data = t4.code
    and t3.ref_code = t2.att_type
    and t2.att_type = 35 and t3.code_type = t4.code_type
    and to_date('01-JAN-10', 'DD-MON-YY') between t2.att_start_date AND t2.att_end_date
    group by t2.org_id) q3,
    (SELECT t2.org_id, t4.description
    from org_name t2, ref_org_name t3, code_table t4
    where t2.att_data = t4.code
    and t3.ref_code = t2.att_type
    and t2.att_type = 1 and t3.code_type = t4.code_type
    and to_date('01-JAN-10', 'DD-MON-YY') between t2.att_start_date AND t2.att_end_date) q4
    Please help me with extracting each alue from the parm '(25,23,35,1)' for the above purpose. Thank You.

    chris227 wrote:
    I would propose the usage of regexp for readibiliy purposes and only in the case if this doesnt perform well, look at solutions using substr etc.
    select
    regexp_substr( '(25,23,35,1)', '\d+', 1, 1) s1
    ,regexp_substr( '(25,23,35,1)', '\d+', 1, 2) s2
    ,regexp_substr( '(25,23,35,1)', '\d+', 1, 3) s3
    ,regexp_substr( '(25,23,35,1)', '\d+', 1, 4) s4
    from dual 
    S1     S2     S3     S4
    "25"     "23"     "35"     "1"In pl/sql you do something like l_val:= regexp_substr( '(25,23,35,1)', '\d+', 1, 1);
    If t2.att_type is type of number you will do:
    t2.att_type= to_number(regexp_substr( '(25,23,35,1)', '\d+', 1, 1))Edited by: chris227 on 01.03.2013 08:00Sir,
    I am using oracle 10g.
    In the process of getting each number from the parm '(25,23,35,1)' , I also need the position of the number
    say 25 is at 1 position.
    23 is at 2
    35 is at 3
    1 is at 4.
    the reason I need that is when I build seperate select for each value, I need to add the query number at the end of the select query.
    Please see the code I wrote for it, But the select query is having error:-
    BEGIN
    IF(pi_flag_codes IS NOT NULL) THEN
    SELECT length(V_CNT) - length(replace(V_CNT,',','')) FROM+ ----> the compiler gives an error for this select query : PLS-00428:
    *(SELECT '(25,23,35,1)' V_CNT  FROM dual);*
    DBMS_OUTPUT.PUT_LINE(V_CNT);
    -- V_CNT := 3;
    FOR L_CNT IN 0..V_CNT LOOP
    if L_CNT=0 then
    V_S_POS:=1;
    V_E_POS:=instr(pi_flag_codes, ',', 1, 1)-1;
    else
    V_S_POS:=instr(pi_flag_codes,',',1,L_CNT)+1;
    V_E_POS:=instr(pi_flag_codes, ',', 1, L_CNT+1)-V_S_POS;
    end if;
    if L_CNT=V_CNT then
    V_ID:=TO_NUMBER(substr(pi_flag_codes,V_S_POS));
    else
    V_ID:=TO_NUMBER(substr(pi_flag_codes,V_S_POS,V_E_POS));
    end if;
    VN_ATYPE := ' t2.att_type = ' || V_ID;
    rec_count := rec_count +1;
    query_no := 'Q' || rec_count;
    Pls help me with fetching each value to build the where cond of the select query along with the query number.
    Thank You.

  • How can I read a specific character from a text file?

    Hi All!
    I would like to read a specific character from a text file, e.g. the 2012th character in a text file with 7034 characters.
    How can I do this?
    Thanks
    Johannes

    just use the skip(long) method of the input stream that reads the text file and skip over the desired number of bytes

  • How to get a formula from the user from a text box in a webpage

    Hi. I would like to know how to get the formula from the user who enters in a textbox. This formula can have any number of variables starting with a and goes on.
    The complexity of the formula can go upto sin, cos, ln, exp. Also user enters the minimum and maximum values of these variables. Based on a specific algorithm (which I use) I would calculate a *set of values, say 10, for each of these variables, substitute in the formula and based on the result of this formula, I select ONE suitable  value for each of the variables.
    I don't know how to get this formula (which most likely to be different each time) and substitute the values *which I found earlier.
    Kindly help me out in this issue.
    Thanks

    The textbox is the easy part. It's no different than getting a String parameter out of an HTTP request.
    The hard part is parsing the String into a "formula" for evaluation. You'll have to write a parser or find one.
    Google for "Java math expression parser" and see what you get.
    Or write your own with JavaCC.
    %

  • How to get specific cell or whatever is in your datatable?

    All there is in my datatable is one value loaded. Here's my code, but how do i convert that datatable to a string?
    var fileName = string.Format("{0}\\file.xlsx", Directory.GetCurrentDirectory());
    var connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.12.0; data source={0}; Extended Properties=Excel 12.0;", fileName);
    OleDbConnection connExcel = new OleDbConnection(connectionString);
    connExcel.Open();
    DataTable xlsData = new DataTable();
    OleDbDataAdapter dbAdapter = new OleDbDataAdapter("select * from [Filters$B2]", connExcel);
    dbAdapter.Fill(xlsData);
    //Now i want to see that value in xlsData???? or possibly convert it since it is only one cell loaded to a string? HELP?

    Hi  vkid,
    >>All there is in my datatable is one value loaded. Here's my code, but how do i convert that datatable to a string?
    About convert datatable to a string, you can use the following code
    string res = String.Join(Environment.NewLine, table.Rows.OfType<DataRow>().Select(x => String.Join(" ; ", x.ItemArray)));
    But based on your title, How to get specific cell,  please check the following code
    string value = table.Rows[0].ItemArray[0].ToString();
    It means get the firstrow and first column value. You can get the specified cell which you want.
    Best regards,
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Strip the first character from a string

    i am trying to strip the leftmost character from a string
    using the following:
    <cfset Charges.DTL_CHG_AMT_EDIT =
    #Right(Charges.DTL_CHG_AMT_EDIT,Len(Charges.DTL_CHG_AMT_EDIT)-1)#>
    i keep getting the following error:
    Parameter 2 of function Right which is now -1 must be a
    positive integer

    > RemoveChars() much easier than Right()? How so?
    Semantically, if the object of the exercise is to *REMOVE
    CHARacters from a
    string* (which it is, in this case), it is simply better
    coding to use
    removeChars() rather than right(). That, and it's one less
    function call
    (the RIGHT() solution also requires a call to LEN() for it to
    work).
    So removeChars() is "easier" because it reflects the intent
    of the exercise
    directly, is simpler logic, is easier to read, and - I can't
    be arsed
    counting keystrokes - is probably less typing.
    That'd be how.
    Adam

Maybe you are looking for

  • Line breaks in URLs sent with Apple Mail

    Does anyone know when/if Apple plans on repairing the flaw in Mail that splits URLs into multiple lines, making it hard for recipients to view recommended links? I recognize there are ways around this including TinyURL, embedding URLs in short words,

  • How to call Java Webdynpro from UWL

    Hi All, How to Call the Java Webdynpro Application from UWL by task? I Know about the TX - SWFVISU, briefly explained about the parameters to be maintanied for approval task from workflow. What all the necessary parameters (settings) to be maintained

  • Reports master-detail-detail

    I am trying to have 1 master group with 2 detail groups. However, when I try to manipulate the columns and groups in the data model, I cannot get the main group to have 2 seperate detail groups. Does anyone know a way to do this without having multip

  • 1z0-897 java web services certification dumps needed

    Hi, Can you please tell me if any one has take the 1zo-897 exam recently and share their experience. Also please post dumps if you get a chance... Thanks Nithin

  • Displaying flat file box

    how to display only the flat file box i.e other boxes should not be displayed in bdc output...send the coding...