Finding multiple occurences of a char in a string

So I am trying to make a check to see if there is more than one comma in an entry such as the following.
"Johnson, Mr. Derrik J."
I figured out that to make sure it has a comma can be...
if (stringHolder[1].indexOf(",") > 0 == false)
System.out.println ("");
System.out.println ("Error G");
So to make sure there are not more than 1 comma would be? I'm stuck.

perhaps the simplest way
if(stringHolder[1].indexOf(",") != stringHolder[1].lastIndexOf(","))

Similar Messages

  • Find first occurence of an integer in a string

    Hi all,
    I have a number of strings which go something like "MBNA Flow 12a" and I want to separate the integer from the rest of the string so I can parse it, sort the strings into some sort of order according to their integer, and then put it all back together again. The problem I'm having is finding the position of the integer within the string, so that I can take a substring and/or split the string. I've looked it up and I gather that using regex I should be able to find the beginning and end of the integer, using something along the lines of           
    Pattern pattern = Pattern.compile("\\d+");
               Matcher matcher = pattern.matcher(temp.getString(1));which I found on another site where someone had the same problem. I've looked at the regex tutorials and according to them this is what I want, but whenever I try it no match is found, and I don't know why. Some sites have claimed that the regular expression has to apply to the entire string, so I would need to also take into account the MBNA Flow etc, something I'm loathe to do as the string is quite unpredictable, but others say that it should work exactly as is.
    Any help would be greatly appreciated. :)
    Thanks.

    silversurfer20 wrote:
    Its throwing the exception cause its not finding a match in the string I know there should be a match in. What I'm wondering is why .Call find() before using either group() or start():
    import java.util.regex.*;
    public class Main {
        public static void main(String[]args) {
            Pattern p = Pattern.compile("\\d+");
            Matcher m = p.matcher("foo 12 bar 34 baz");
            if(m.find()) {
                System.out.println("first number: "+m.group()+", starts at index: "+m.start());
            } else {
                System.out.println("nothing found");
    }Output:
    first number: 12, starts at index: 4

  • How to find multiple occurences in Hashtable

    I have a hashtable in which elements are stored with their values. Elements (keys) are labelled as
    Dept_1_2
    Dept_1_3
    Dept_2_3
    etc
    Now if I want to access all occurrences that start with letters Dept, how can I do that?? Should I use some kind of Regular Expression for pattern matching or is there other way?
    Thanks in advance

    Hashtable doesn't provide any method to do this. You will have to write a function that looks through the keys (hashtable.keys()) and perform the check (key.startsWith("Dept")) for each key.

  • Finding last char in the string

    Hi
    i need to find out whether the last char of a string is '/' (forward slash). please let me know if there's a FM to do that. Other post me the logic for this ASAP.
    thanks

    len = strlen(char).
    len = len - 1.
    if char+len(1) = '/'.
      *write ur code
    endif.
    chk this code
    REPORT ychatest.
    DATA : str(5) VALUE '123/',
           len TYPE i.
    len = STRLEN( str ).
    len = len - 1.
    IF str+len(1) = '/'.
      WRITE : '/ found'.
    ENDIF.
    <b>Reward points if helpful and close thrad if solved</b>
    Message was edited by: Chandrasekhar Jagarlamudi

  • Finding multiple strings in a text file and deleting the entire line

    Get-Content c:\output-Copy.txt | Where-Object {$_ -notmatch 'something1', 'something2', 'something3', 'something4' } | Set-Content temp.txt
    Above is the program that when it has 1 argument in the -notmatch part will find the specific string and delete the entire line. I need to be able to use multiple strings for my search, I am totally drawing a blank on this and I know its something REALLY
    simple but my brain is fried. The above code will work IF i only leave 'something1' and delete the rest. I need to find MULTIPLE matches and remove them all at once, what is a good way to accomplish this.

    You can use an alternating regex, like this:
    Get-Content c:\output-Copy.txt |
    Where-Object {$_ -notmatch 'something1|something2|something3|something4' } |
    Set-Content temp.txt
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • Detecting multiple occurences of a value in data? (conundrum)

    Ok, if there are any good java utilities to help, this is where I'm going to find them...
    I'm trying to detect multiple occurences in a data set. Piling them into an array and using Array.sort() was a good start - I'm trying to find the max and min value of data that occurs more than once in the set.
    However, when the data set becomes much larger, I can't hold the set in memory. Is there an elegant solution to this? I'm at a loss to find a nice way of doing it. Its an interesting problem...
    Thanks,
    Steve

    Hi Steve!
    You can do this with a bit of programming yourself :-) If all values don't fit into your memory, just split them into smaller pieces. Do you need to sort out all duplicates or do you need to detect them only?
    The idea:
    Create a new ArrayList oder a Set of your choice and put some elements in it (a fixed number or just wait for an OutOfMemoryException to be thrown and catch this). Then sort the ArrayList and write it to a temporary file, store the file handle or name in a seperate list. Go on like this until all your data is sorted.
    After that, build one loop fetching just one value from each file and compare them - mainly this is mergesort. If duplicate values occur then, well, you have dupes :-)
    If needed I could look for the source...
    Cheers,
    Jan

  • Counting the Multiple Occurence of a record in the internal Table-Urgent

    Hi,
    I have an internal table with the following values
    a
    a
    a
    b
    b
    b
    c
    c
    I need to print a-2
                         b-3
                         c-2
    How do i accomplish this? i.e.,I need to count the multiple occurence of a field.Any input on this will be of great help.
    Thanks and Regards,
    Pavithra

    Hi,
    Find the piece of code below it can help you:
    data: begin of itab occurs 0,
               field1 type c,
               field2 type i,
            end of itab.
    data: itab2 like table of itab occurs 0 with header line.
    data: count type i.
    start-of-seleciton.
    itab-field1 = a.
    append itab.
    itab-field1 = a.
    append itab.
    itab-field1 = a.
    append itab.
    itab-field1 = b.
    append itab.
    sort itab by field1.
    loop at itab.
      count = count + 1.
    at end of field1.
      clear itab2.
      itab2-field1 = itab-field1.
      itab2-field2 = count.
      append itab2.
    endat.
    endloop.
    Dispaly output table.
    loop at itab2.
      write:/ itab2-field1, itab2-field2.
    endloop.
    Reward the points if it is helpful.

  • How to replace multiple occurences of space in a string to a single space?

    How to replace multiple occurences of space in a string to a single space?

    Hi,
    try this code.
    data : string1(50) type c,
              flag(1) type c,
              dummy(50) type c,
              i type i,
              len type i.
    string1 = 'HI  READ    THIS'.
    len = strlen( string1 ).
    do len times.
    if string1+i(1) = ' '.
    flag = 'X'.
    else.
    if flag = 'X'.
    concatenate dummy string1+i(1) into dummy separated by space.
    clear flag.
    else.
    concatenate dummy string1+i(1) into dummy.
    endif.
    endif.
    i = i + 1.
    enddo.
    write : / string1.
    write : / dummy.

  • Bridge CS6 Script to Find Multiple Images in Multiple folders.

    Is it possible to have a script to find multiple images within multiple folders that is on a external hard drive?
    For instances I have a external hard drive assuming it's for a library of pictures.
    Inside this hard drive has folders named as below
    1-1000
    1001-2000
    2001-3000
    3001-4000
    If I had a perfect csv file for example that calls out for specific pictures for example 2, 10,1500 and 2000 (remember think big, it may be a larger list than this it could be hundreds or thousands of pictures); is there a script that would allow me to find these images and save a copy of them on to my desktop so that way I don't have to hunt for them in the old fashion way? I can read scripts but writing them is a different story.

    If you want to go with Batch I would recommend creating an Action of more or less these steps:
    • set the resolution to the same as the background image’s
    • change the image from Background Layer to regular Layer if necessary
    • convert it to a Smart Object
    • add a Drop Shadow Layer Style to the image (do not use Global Angle)
    • place the background image (File > Place …)
    • move it behind the image layer
    • Image > Reveal All
    • make Selection from that layer’s transparency (cmd-click its icon in the Layers Panel) and use Image > Crop
    • select and transform the image layer to fit the intended position
    This would naturally work out best if the images had the same size and proportions.
    For the reflection on the floor duplicate the image, flip it vertically, move it in position and reduce its opacity to maybe 10%.
    Realistically you may have to hide it partially behind the pillows, a Vector Mask would be an option.

  • Find multiple formats in one search?

    Is there any way I can find multiple formats in one search? I need to find all instances of a paragraph style that comes after another paragraph style.

    Sorry, no, the Find/Change function doesn't permit that.
    You could export to InDesign Tagged Text and manipulate that text file with an external tool...

  • Multiple occurence not working for extended idocs

    hai friends
    iam doing file to idoc senario in that multiple occurence is not working for Z segments.
    it is extented idoc .
    in taht multilpe segments are not creating only one segment is creating
    what is the problem
    pls help me
    with regards
    srikanth vipparla

    Hi Srikanth,
    You should map the node of the target side(the one which you want to occur multple times) to the node of the source side based upon which the target side node has to occur multiple times. For example lets say our source and target side structures are like this:
    <Source>
                  <Element1>
                  <Element2>
                  <Element3>
    </Source>
    <Target>
                  <Element1>
                  <Element2>
                  <Element3>
    </Target>
    Now if you want Target to occur n times if  Source node occurs n times, you should map Target node to the Source node. Even in case you want that Element1 of target side should occur as many times as many times you have Element1 of Source side, you should do the same.
    Thanks and Regards,
    Sanjeev.
    PS: Reward points if helpful.

  • Where i can find multiple confirm qty with multiple schedule line..

    Hi Experts,
    Is there any BAPI  FM or FM for finding multiple schedule line confirmation with some of blocked.
    Yusuf

    not solved

  • Finding char in a string

    Hi,
    In C there is a function strchr() to find a char in a string. Is there an equivalent funtion in Java?
    The function indexOf() returns an int, but I want this char search would return a boolean value.
    So help please, thanks a lot
    chanh

    public boolean strchr(char myChar, String myString){
       for(int j = 0; j < myString.length(); j++){
          if(myChar == myString.charAt(j) return true;
       return false;
    }Is this what you are looking for?

  • Oracle query to get all occurences of a text in a string

    Hi
    Does anybody know how to write a query to get all occurences of a text in a string in different rows of the table
    For eg:
    I have a string <aa>bb</aa><aa>cc</aa><aa>ddd</aa>
    I have to find every occurence of <aa> and get the data between <aa> and </aa>
    So the output should be
    bb
    cc
    ddd
    I think this can be done by using a regular expression but I dont know how.
    Can anyone help me?
    Thanks in advance.

    user2360027 wrote:
    BluShadow,
    The query gives correct results if i only have <aa></aa>
    What if i have <ff></ff>?
    Example:
    <aa>bb</aa><aa>cc</aa><aa>ddd</aa><ff>dsd</ff>
    I want to have the following (dsd should not be there in the result)
    bb
    cc
    dddThis is a new requirement and not what you asked for in your original post. Perhaps you should tell us exactly what you are trying to achieve and what database version you are using to save us guessing.
    To crokitta,
    This version will deal with multiple rows..
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select '<aa>bb</aa><aa>cc</aa><aa>ddd</aa>' as x from dual union all
      2             select '<aa>xx</aa><aa>yy</aa>' from dual)
      3  -- end of test data
      4  select x, vals
      5  from (
      6    select x, regexp_replace(REGEXP_SUBSTR (x, '>[^<]+', 1, lvl),'[<>]') as vals
      7    from t
      8        ,(select level lvl from dual connect by level <= (select max(length(regexp_replace(x,'[^>]*'))/2) from t))
      9    )
    10  where vals is not null
    11* order by 1,2
    SQL> /
    X                                  VALS
    <aa>bb</aa><aa>cc</aa><aa>ddd</aa> bb
    <aa>bb</aa><aa>cc</aa><aa>ddd</aa> cc
    <aa>bb</aa><aa>cc</aa><aa>ddd</aa> ddd
    <aa>xx</aa><aa>yy</aa>             xx
    <aa>xx</aa><aa>yy</aa>             yy
    SQL>

  • I need to WAP to count the number of occurences of an alphabet in a string.

    I need to WAP to count the number of occurences of an alphabet in a string.I tried a lot and have surfed a lot regarding this problem.
    I m not the most proficient with java.but this is all i could come up with,and would appreciate some help here.I hope you guys would help me find a solution to this.
    e.g String : abcabrty
    Result should be
    a:2
    b:2
    c:1
    r:1
    t:1
    y:1
    public class chkoccurences
         public static void main(String args[ ])
              String user_Data=args[0];
              int counter=0;     
              try
                   for(int i=0;i<user_Data.length( );i++)
                        for(int j=0;j<user_Data.length( );j++)
                             if(user_Data.charAt(i) == user_Data.charAt(j))
                             counter++;
                        System.out.println(user_Data.charAt(i)+" exists "+counter+" time(s) in the word.");
                   System.out.println(" ");
              catch(ArrayIndexOutOfBoundsException e)
                   System.out.println("Check the array size.");
    }This is the output i get out of the program:
    a exists 2 time(s) in the word.
    b exists 4 time(s) in the word.
    c exists 5 time(s) in the word.
    a exists 7 time(s) in the word.
    b exists 9 time(s) in the word.
    r exists 10 time(s) in the word.
    t exists 11 time(s) in the word.
    y exists 12 time(s) in the word.What i think is i need an array to store the repeated characters because the repeated characters are getting counted again in the loop,if you know what i mean.
    Please, i would appreciate some help here.

    Criticism is welcomed
    public class tests {
         final int min = 10;
         final int max = 35;
         final char[] chars = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
                   'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
                   'v', 'w', 'x', 'y', 'z'};
         public static void main(String[] args){
              tests t = new tests();
              String[] strings = new String[] {"aabcze", "att3%a", ""};
              for(String s : strings){
                   System.out.println(t.getAlphaCount(s));
         public String getAlphaCount(String s){
              int[] alphaCount = new int[26];
              int val;
              for(char c : s.toCharArray()){
                   val = Character.getNumericValue(c);
                   if( (val>=min) && (val<=max)){
                        alphaCount[val-min]++;
              StringBuilder result = new StringBuilder();
              for(int i=0; i<alphaCount.length; i++){
                   if(alphaCount[i] > 0){
                        result.append(chars[i] + ":" + alphaCount[i] + ", ");
              if(result.length() != 0){
                   result.delete(result.length()-2, result.length());
              return result.toString();
    }

Maybe you are looking for

  • Windows server 2008 R2 won't update

    I have a Windows Server 2008 R2 which won't install updates coming from a WSUS server.  All other servers are installing updates fine.  They fail with the code 52D.  If i look at the Application Event log i can see the install start but then each upd

  • On windows 8 adobe touch reader, where do i get options to validate/verify digital signatures in pdf?

    i have windows 8 OS in my laptop, i need to verify digital signatures present in my pdf. the steps to verify/validate them are- 1. Open the PDF file in PDF Reader. 2. Left-click on the Digital Signature field. 3. Click "Verify/Validate Signature". 4.

  • HP Remote Connection

    The HP remote service is always running and slowing down my computer.  Will it harm my computer to remove it?  I don't need to pair my computer with any other devices or networks.  Any help is appreciated.  Thanks. This question was solved. View Solu

  • How do I get mac to use my server!

    Ok this is probably the simplest question, and yet I don't anything anywhere that tells me how to do this. I installed a Tiger server on a small network and I have 4 regular macs running Tiger. How do I tell the macs to login using the server? I want

  • I-tunes is randomly changing album names

    Every time I click on a song, itunes changes the name of the album to random music. This suddenly started happening a few weeks ago (about the same time as our 16 year old border started using the computer!). Also when I go in to see the info on the