Count Substring in String

Is there any way you can count the number of substrings in a
string using Coldfusion?
E.g.
haystack = 25fdjkkjlafjkl25alksdfjaafdjk25sl
needle = 25
result = 3

eightcharacters wrote:
> True - In my case I was looking to count the number of
slashes in a file/directory name from cfdirectory to determine how
deep a file was in that directory.
Do you want the number of slashes or the number of elements
between the
slashes?
If the latter the more common code would be:
<cfoutput>#listLen("Path/To/My/File.txt","/")#</cfoutput>

Similar Messages

  • Find Substring in String in Workflow

    I'm trying to separate the content from GUID with metadata, but I can't find the Find Substring in String function in SharePoint Designer 2013 mentioned on
    MSDN. Can anyone provide guidance? Thanks!

    Its a not a function. It is workflow action under Actions menu in your SPD 2013. 
    You can find that action under the Utility Actions and make sure you have selected All Actions as show in the image above.
    Amit

  • Count integers in String array

    String[] s= {"xx","yy","34","35","46"};
    i want to count the integers in that String array.
    output: 3
    Can any one suggest me how to get that one.

    Try it again with this String in your
    array:"2147483648"
    Ok if you have to account for very large integers then you could use the following:
    String[] array = {"xx","yy","34","35","46", "2147483648"};
    int count = 0;
    for (String s : array) {
         boolean numericOnly = true;
         for (char c : s.toCharArray()) {
              if (c >= 48 && c <= 57) {
                   // Int value
              else {
                   numericOnly = false;
         if (numericOnly)
              count++;
    System.out.println("" + count);

  • Substring for Strings, what do I use for a int variable???

    Hi!
    substring for Strings...
    String s1 = p.substring(1,2);
    but what do I use for a int variable?
    int i1 = integ."???????"(1,2);
    /Henrik

    why, you use maths of course!!
    or if you're not up to that, try this:
    int x = 931;
    String s = x+"";
    String res = s.substring(1, 2);
    and of course set it back to an int
    with Integer.parseInt(res);

  • Substring of string seperated by commas

    Hi All,
    I am trying for a logic that i have some emp ids as a string seperated by commas and i need the substring of emp ids as below.
    Can any one help in splitting the string as below.
    public static void main(String args[]) {
             String empId = "1,2,3,4,5,6,7,8,9,10";
            int i;
               int count = 9;
               for (i = 0; i <= count; i = i + 3)
                 System.out.println("Emp IDs are : " +empId);
                  Result is:
    Emp IDs are : 1,2,3,4,5,6,7,8,9,10
    Emp IDs are : 1,2,3,4,5,6,7,8,9,10
    Emp IDs are : 1,2,3,4,5,6,7,8,9,10
    Emp IDs are : 1,2,3,4,5,6,7,8,9,10
    But i want the result like:
    Emp IDs are : 1,2,3
    Emp IDs are : 4,5,6
    Emp IDs are : 7,8,9
    Emp IDs are : 10
    thanks for your help.

    It can be helpfull to split the question into smaller pieces.
    How many id's do you have. When you have the complete String use
    //put the string in an array
    String[] stringToArray = longIdString.split(",");
    //How any id's
    int numberOfIdInArray = stringToArray.length;'
    Now you know the number of id's.
    Divide the number by 5 and you know the number of id's in one new line
    Then make 2 loops. For 5 times add the original string with a begin and endpoint in a new string.
    package test;
    public class SplitString {
      public static void main(String[] args) {
      //the initial id's
      int numberOfIds = 5000;
      final int NUMBEROFLINES = 5;
      //Make a long string
      String longIdString = "";
      StringBuilder builder = new StringBuilder();
      for(int i = 1; i <= numberOfIds; i++){
      builder.append(i + ",");
      longIdString = builder.toString();
      System.out.println("Original Array: " + longIdString);
      //put the string in an array
      String[] OriginalArray = longIdString.split(",");
      //How any id's
      int numberOfIdInOriginalArray = OriginalArray.length;
      System.out.println("Number of Id's: " +numberOfIdInOriginalArray);
      //Number of id's in one row
      int numberOfIdInOneRow = numberOfIdInOriginalArray / NUMBEROFLINES;
      System.out.println("Id's in one row: " + numberOfIdInOneRow);
      //Make 5 strings and put them in a new array
      String[] theNewStrings = new String[NUMBEROFLINES]; //Aray where you can store the new Strings
      int startpoint = 0;
      int endpoint = startpoint + (numberOfIdInOneRow);
      for(int i = 0; i < NUMBEROFLINES; i++){
      StringBuilder buildNewString = new StringBuilder();
      for (int j = startpoint; j < endpoint; j++){
      //Remember that the first value in an array is at index 0
      buildNewString.append(OriginalArray[j] + ",");
      theNewStrings[i] = buildNewString.toString();
      //Create a new start and endpoint for the next String
      startpoint = startpoint + numberOfIdInOneRow;
      endpoint = startpoint + (numberOfIdInOneRow);
      //Print the new 5 strings
      for(int i = 0; i < theNewStrings.length; i++){
      System.out.println(theNewStrings[i].toString());
    In the "real world" you have to program the rounding of the division.

  • Vowels and consonants count of a string

    Hi...
    1.    plz provide code for counting no of  vowels and        Consonants   in a STRING.... suppose the string is BUSINESS.
    and also other
    2.     program to pass the string during runtime and couting vowels,consonants and also checking whether the string is palindrom or not.
    plz send me the code asap...
    Regards
    Narin.

    Hi,
       DATA :  v_string(40) VALUE  'BUSINESS',
                  v_cnt1 TYPE I,
                  v_cnt2 TYPE I VALUE 1,
                  v_len TYPE I,
                  v_num(10),
                  v_diff TYPE I,
                  v_vowels TYPE I ,
                 v_conso TYPE I.
    START-OF-SELECTION.
      v_len =  strlen( v_string ).
       DO v_len TIMES.
         IF v_string+v_cnt1(v_cnt2)  CA  'A,E,I,O,U'.
            v_vowels =  v_vowels  + 1.
         ELSE.
          v_conso =  v_conso + 1.
         ENDIF.
           v_cnt1 =  v_cnt1 + 1.
       ENDDO.
      WRITE : v_vowels  , v_conso.

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

  • How to get substring from string starting from the end of string

    Hi
    How to cut from string:
    $A=C:\ClusterStorage\Volume1\WXP-plwropc300\Virtual Hard Disks\WXP-PLWROPC300_EE20E00F-315E-4781-A6DE-68497D4189B8.avhdx
    this substring (name of VHD file): WXP-PLWROPC300_EE20E00F-315E-4781-A6DE-68497D4189B8.avhdx
    This script should be universal so the best way to be cut all leters from the end of string $A till get the first mark \
    Thank you for help.
    Tomasz
    Kind Regards Tomasz

    PS > Split-Path 'C:\ClusterStorage\Volume1\WXP-plwropc300\Virtual Hard Disks\WXP-PLWROPC300_EE20E00F-315E-4781
    -A6DE-68497D4189B8.avhdx' -leaf
    WXP-PLWROPC300_EE20E00F-315E-4781-A6DE-68497D4189B8.avhdx
    PS >
    That is what "Split-Path" is for:
    ¯\_(ツ)_/¯

  • How to get substring from string using index?

    hi,
    here i am having string ,
    i want the pullareddy from below line ,
    i know how to get from substring.
    but i want to get the above using "index",
    can any help how to do it?
    String str1="janapana,pullareddy, in malaysia";
    jpullareddy

    get the start index with indexAt("pullareddy")
    get the end index with adding the length of the word to the start
    get the char[] of str1 with toCharArray()
    make a new string with the chars from start to end index.

  • Count from a string

    i am using this formula
    {USR_CR_RISK_CHANGE;1.DETAIL}[instrrev({USR_CR_RISK_CHANGE;1.DETAIL},'OLD: LowRisk')-1 to length({USR_CR_RISK_CHANGE;1.DETAIL})];
    this retrieves
    OLD: LowRisk NEW: MediumRisk
    which is what i want
    i want to then get a count of how many risk changes there were from low to medium
    the original string looks like this
    | LastOper OLD: SQLUSER NEW: LUCI01| LastModify OLD: May 11 2009 10:03AM NEW: May 11 2009 12:17PM| RiskClass OLD: LowRisk NEW: MediumRisk
    if there is a way to get a count from the original string that would work also
    thanks

    if instr({@OLD LOW RISK},'LowRisk') > 0
    and
    instr ({@OLD LOW RISK},'MediumRisk')>0 then
    1 else 0
    This seems to work

  • How to count characters in string

    i have a string like
    a,a,b,b,s,a,a,b,ba
    requried out put is
    count(a)=5
    and count(b)=4
    count(,)=8
    thanks &regards
    nataraj kesana

    if your db version is Oracle 11g,
    you can use below one,
    SELECT regexp_count('a,a,b,b,c,c,d,d,e,a,a,b,d,c','a') a_count,
      regexp_count('a,a,b,b,c,c,d,d,e,a,a,b,d,c','b') b_count,
      regexp_count('a,a,b,b,c,c,d,d,e,a,a,b,d,c','c') c_count,
      regexp_count('a,a,b,b,c,c,d,d,e,a,a,b,d,c','d') d_count,
      regexp_count('a,a,b,b,c,c,d,d,e,a,a,b,d,c','e') e_count
    FROM dual;
    and output will be
    a_count|b_count|c_count|d_count|e_count
    4         |   3       |    3      |    3      |1

  • Detect substring in string

    Hi all,
    I am new to ABAP and hoping you guys can let me know if there is a better way to check for a substring in a string.
    I need to detect a substring (or should call it a word) 'CNF' in a string, and it need to be a word itself and not part of another word (example, PCNF). This substring can appear in the beginning of the string or the end of the string. To explain this clearly let me show you a list of string that should return me true or false:
    Return true:
    MCNF CNF REL
    CNF MCNF REL
    CNF REL
    REL CNF
    MCNF REL CNF
    Return false:
    MCNF PCNF REL
    REL MCNF PCNF
    One way i think of doing it is to split it using space into a itab, loop thru and check. Is there a better way to do this?

    Hello,
    Please look at the example below:
    Example
    DATA F(50).
    MOVE 'Alaska Texas California' TO F.
    SEARCH F FOR 'Clfrn' ABBREVIATED.
    Here, SY-SUBRC is set to 0, since not only does the string 'Clfrn' occur (separated by other characters) in 'California', but 'Clfrn' and 'California' begin with the same letter.
    Addition 2
    ... STARTING AT n1
    Effect
    Searches the field f starting from the position n1. Here, n1 can also be a field containing the corresponding value. The first character in the field f is in position 1.
    When you use the addition STARTING AT, the position specified for the found pattern in SY-FDPOS does not refer to the start of the field, but to the position n1.
    Addition 3
    ... ENDING AT n2
    Effect
    Searches the field f up to the position n2.
    Addition 4
    ... AND MARK
    Effect
    If the search string g is found, all the characters of the search string and all the characters occurring in between (in the case of SEARCH ABBREVIATED) are converted to upper case in the field f.
    Example
    DATA F(20) VALUE 'Peter Paul Mary'.
    SEARCH F FOR '*UL' AND MARK.
    SY-SUBRC is now set to 0, since the search string was found in 'Paul'. SY-FDPOS has the value 6, since the character string found starts at the offset 6. Also, the search string is marked, so that the new contents of f are as follows:
    'Peter PAUL Mary'
    Hope this helps...
    P.S. Please award points for useful answers.

  • Count Occurrences of String in Cell Range

    I have a column like this:
    Header 1
    AA
    AA, BB
    BB
    BB, AA
    AA
    I need to count how many times "AA" appears throughout this column, so in this case the answer should be 4. I've tried searching for hours, but can't find anything. Anyone have any ideas?
    Thanks!

    Hi G,
    COUNTIF, using wildcards can count the number of cells containing the specific string.
    The example below shows the results where a cell contains AA more than once. C2 contains the same formula as above. C4 contains =SUM(B). Cells in column B use LEN() and SUBSTITUTE to calculate the number of times AA appears in each row of column A.
    A2, and filled down: =(LEN(A2)-LEN(SUBSTITUTE(A2,B$1,"")))/LEN(B$1)
    Regards,
    Barry

  • To find substr within string

    Hello,
    I have a string (column is normal range) like 70 - 110 mg/dl.
    I wanted to separate 70 and 110.
    For 70 i am using like this
    select substr(normal_range,1,instr(normal_range,'-')-1) from m_parameters where normal_range='70-110 mg/dL'. It works.
    But how to get 110.
    Some rows may also be 110-209 U/L without any space between '-'.I want a query which works for all conditions.
    Conditions are.
    1. 70 - 110 mg/dL
    2. 70-110mg/dL
    3. 70 -110mg/dL
    4. 70- 110mg/dL
    5. 70-110 mg/dL
    thanks
    Swapna

    Hi Swapna,
    Using the old-fashioned SUBSTR and INSTR combination:
    SQL>   with t
      2  as
      3  (
      4  select '0.3 - 1.0 mg/dL' str from dual union all
      5  select '70 - 110 mg/dL' str from dual  union all
      6  select '70-110mg/dL   ' str from dual  union all
      7  select '70 -110mg/dL  ' str from dual  union all
      8  select '70- 110mg/dL  ' str from dual  union all
      9  select '70-110 mg/dL  ' str from dual
    10  )
    11  select trim(substr(str, 1, instr(str, '-') - 1)) num1,
    12         trim(substr(str, instr(str, '-') + 1, instr(str, 'mg') - instr(str, '-') - 1 )) num2
    13    from t;
    NUM1            NUM2
    0.3             1.0
    70              110
    70              110
    70              110
    70              110
    70              110
    6 rows selected.
    SQL>Asif Momen
    http://momendba.blogspot.com

  • How to make substring a string in concern with length

    hello frds,
    i am in need of a very basic clarification.
    i have a String like
    String st="abcdefg";
    String st1=st.substring(0,2);
    String st2="ab"
    i am getting st1="ab" like what need
    but the when i compare st1 and st2 its not returning true (but it shows the same values while debugging)
    its because the st1 object is contains length greater that st2.
    i tried st1.trim() also
    any help
    thanks

    but the when i compare st1 and st2 its not returning
    true (but it shows the same values while debugging)Let me guess. You aredoing something like this.
    System.out.println(st1 == st2);Use the equals() method to compare Strings, not ==.

Maybe you are looking for

  • Acrobat 9 Standard Trial Download

    I have been able to download the trial version 9 Pro and have done my testing, but I've not been able to find and download a trial version of Acrobat 9 Standard.  I'm guessing it is not available for trial, can anyone confirm please? Thanks, Jeffrey

  • For loop don't updates

    Hi, First I'm new at labview , I'm trying to read 8 checkboxs vals and for each checkbox I'm queuing a single val witch will be a test. I have a problem with my for loop it simply won't update and staying at 0 val ( only one iteration )  vi is attach

  • Zoom-in keyboard shortcut not working in illustrator CC

    I am able to use the keyboard shortcut control+minus to zoom out, but control+plus/= to zoom in has stopped working in illustrator CC. (It works fine in illustrator CS6.) Any idea how to fix this?

  • Export with Previous... does not export like previous!

    Hello,      I As far as I remenber, "Export with Previous..." always exported like the previous export. Unfortunatly, since some times, this function exports only to my "Full - Tiff8" settings.   Is there any way to fix this settings ?   I am using L

  • Firefox won't let me enable the setting to re-open my last session from ethere hostory or the main settings how can i fix??

    i got to the menu-settings-geniral-i only have use home page or a blank page it will not allow me to select in-order to re-store my last session and same in the history menu it wont allow me to click on it!