Finding the occurences of | character in a string

Hi There,
I want to restrict the occurrences of | character in a string to some number. How can I make this check using regular expressions.
Thanks,
--JJ                                                                                                                                                                                                                                                                                                                               

sabre150 wrote:
guitar_man_F wrote:
sabre150 wrote:
jose wrote:
So can you please suggest me a sample regex which will do this.
--JJErr.. err.. err.. reply #2?Not quite. I believe he said restrict it to a certain max number of |, not remove all instances. I think.
Look again. I remove anything that is NOT a '|' char and then count what is left.Oops! My bad! You're right. That would work.
- Adam

Similar Messages

  • How can if find the most repeated character and number ???

    Hi,
    I have a question. For instance, if we have a text file which contains:
    aaabbbhhhhhhtttttsjs12366
    How can i find the most repeated character and number. I have to add this code to the following program:
    I will aprreciate if you can help.
    Regards,
    Serkan
    import java.io.*;
    public class LineLen {
         public static void main(String args[]) throws Throwable {
              final String filename = "deneme1.txt";
              BufferedReader infile = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
              String line = infile.readLine();
              int linenum = 0;
              while (line != null) {
                   int len = line.length();
                   linenum++;
                   System.out.print(linenum + "\t");
                   for (int i = 0; i<len; i++)
                   System.out.print("*");
                   System.out.println("");
                   line = infile.readLine();
    }

    For a small alphabet like English, array migt be used:
    //in a for loop
    ++array[s.charAt(i)];For a big alphabet like chinese, HashMap might be barely used:
    map.put(s.charAt(i), increment(map.get(s.charAt(i))));
    // increment is a user defined method, possibly for an Integer object,
    // that returns a new Integer object

  • Which method to count the number of character in a string?

    Hi all,
    I want to know which class and method to count the number of character in a string?
    Gary

    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html

  • Find and print illegal character in a string using regexp

    I have the following simple regexp that checks for illegal characters in a string:
    String regexp = ".*([\\[\\];]+|@).*"; // illegal: [ ] ; @
    String input = "Testing [ 123";
    System.out.println(Pattern.matches(regexp, input));How can I find and print the character that is invalid??
    I've tried using the Matcher class togheter with Pattern but cant get it to work. :(
    Like this:
    Pattern pattern = Pattern.compile(regexp);
    Matcher matcher = pattern.matcher(input);
    matcher.lookingAt();
    int matchedChar = matcher.end();
    if (matchedChar < input.length()) {
        String illegalCharFound = String.valueOf(input.charAt(matcher.end()));
        System.out.println(illegalCharFound);
    }What am I doing wrong?

    1. You call lookingAt(), but you don't check its return value, so you don't know if the regex actually matched.
    2. matcher.end() returns the index of the character following whatever was matched, assuming there was a match (if there wasn't, it will throw an exception). So either it will point to a legal character, or you'll get a StringIndexOutOfBoundsException because an illegal character was found at the end of the input. The start() method would be a better choice, but...
    3. Your regex can match multiple consecutive square brackets or semicolons (and why not put the at-sign in the character class, too?), but you're acting like it can only match one character. Even if there is only one character, group(1) is an easier way to extract it. Also, if there are more than one (non-consecutive) illegal characters, your regex will only find the last one. That's because the first dot-star initially gobbles up the whole input, then backtracks only as far as it has to to satisfy the rest of the regex. If your goal is to provide feedback to whoever supplied the input, it's going to be pretty confusing feedback. You should probably use the find() method in a loop to pick out all the illegal characters so you can report them properly.

  • Occurence of character in a string

    How can i find how many occurrence of a character in a string?
    Let's say: 010101010101010: there is 8 0 in that string.

    Here's just a different take on the same old problem, tested on 10g ... ;-)
    WITH t AS (SELECT '010101010101010' col1
                 FROM dual
    SELECT SYS_CONNECT_BY_PATH(symbol || ':' || TO_CHAR(no_of_sym), ' ') sym_stat
      FROM (SELECT SUBSTR(t.col1, LEVEL, 1) symbol
                 , COUNT(*)                 no_of_sym
                 , ROW_NUMBER() OVER (ORDER BY SUBSTR(t.col1, LEVEL, 1)) rn
              FROM t
           CONNECT BY LEVEL <= LENGTH(t.col1)
             GROUP BY SUBSTR(t.col1, LEVEL, 1)
    WHERE connect_by_isleaf = 1
    START WITH rn = 1
    CONNECT BY PRIOR rn = rn - 1
    => "0:8 1:7"C.

  • How to find the number of occurance of a string in text field of Infopath form?

    Hi All,
    In Infopath text field, How to find the number of occurrence of a particular string in that field?
    Thanks in advance!

    You can check to see if it contains a string once by using the contains function, but there isn't a very clean way to do what you want. If you wanted to guess at the maximum number of occurrences, then you could:
    Box A has your initial. Set Box B to do a concat of string-before and string-after of Box A where it copies Box A minus the string we're looking for. Then we have Box C that does the same thing to Box B. Repeat as many times as you see necessary.
    Example:
    String: "1"
    Box A - "123451234512345"
    Box B - "23451234512345"
    Box C - "2345234512345"
    Box D - "234523452345"
    etc.
    We then have a field that has nested ifs looking backwards from Z -> A looking for a non-blank. Based on that, we return the number of occurrences. Again, this isn't clean, but it will work if you think there's a predefinable maximum.
    Andy Wessendorf SharePoint Developer II | Rackspace [email protected]

  • How to replace only the first specified character in a string and leave other occurrence of the character alone.

    Hello my Friends:
    I have a string that looks like this in a column:
    Hello, World, Hello, Planet
    I want to replace only the first occurrence so that the result looks like this:
    Hello World, Hello, Planet
    Working on some bad data source.
    I need to replace the character regardless of it's location as long as it is the first.
    I tried something like this, but I soon discovered that if the comma or character is missing the the string may get truncated or altered. If there are no characters in the string, then I want to simply leave it alone.
    Here is where I am at:
    DECLARE @MyValue NVARCHAR(MAX) = 'Hello, World, Hello, Planet';
    SELECT MyString = STUFF('Hello, World', CHARINDEX(',', @MyValue, 0), 1, ' ');
    Thanks my friends.

    I have a string that looks like this in a column:
    Hello, World, Hello, Planet
    Why doesn't it say Hello Kitty?
    Oh, sorry about that. Anyway:
    SELECT MyString = CASE WHEN CHARINDEX(',', @MyValue, 0) >= 1
                           THEN STUFF(MyString, CHARINDEX(',', @MyValue, 0), 1, ' ')
                           ELSE MyString
                     END;
    Erland Sommarskog, SQL Server MVP, [email protected]
    Erland, love you sense of humor!! :)
    Thanks for the solution.

  • Can't find the right way to parse a string

    Hi to all,
    I am new to Lab-View, coming from a "C" background. I have spent all afternoon trying to get something to work, with no success. I am looking for a way to read files that are named sequentially, with a common prefix. For example:
    "abc2004_001.tst", "abc2004_002.tst",... .
    These file are not generated by LabView and the problem is that the file counter does not have a fixed width (can be 2, 3, 4, ... character wide) and the file prefix is alpha_numeric.
    What I would like to do is to select the first file in the sequence and let LabView generate all other name, incrementing the sequence number, until a file-not-found.
    I've tried using regular expression but cannot make it work when the file name prefix contains
    a number.
    Any suggestion...
    Thanks!
    MichelB

    MichelB wrote in news:5065000000080000000BF00000-
    [email protected]:
    > Hi to all,
    > I am new to Lab-View, coming from a "C" background. I have spent all
    > afternoon trying to get something to work, with no success. I am
    > looking for a way to read files that are named sequentially, with a
    > common prefix. For example:
    > "abc2004_001.tst", "abc2004_002.tst",... .
    > These file are not generated by LabView and the problem is that the
    > file counter does not have a fixed width (can be 2, 3, 4, ...
    > character wide) and the file prefix is alpha_numeric.
    > What I would like to do is to select the first file in the sequence
    > and let LabView generate all other name, incrementing the sequence
    > number, until a file-not-found.
    > I've tried usin
    g regular expression but cannot make it work when the
    > file name prefix contains a number.
    > Any suggestion...
    > Thanks!
    > MichelB
    Suggestion 1:
    Use the "Scan From String" function
    (Function palette->String->Scan From String)
    Wire your input string to "Input String"
    Wire this string constant "%[^_]_%d" to "Format String"
    Expand the outputs to get two outputs.
    The format string does this (string is divided in three)
    %[^_] Extract all characters which is not _
    _ Match the _
    %d Exctract a decimal number
    Suggestion 2:
    Use the "Match Pattern" function
    (Function palette->String->Match Pattern)
    with the string "[a-zA-Z0-9]_" as the "regular pattern" input
    The "after substring" output should hold the number(+filename ending)
    If you have an array with input file names (e.g. from the "List Directory"
    file function) then you have to use a for or while loop.
    Hope this helps.
    Rolf

  • How to find the mode of an array of strings

    Hey guys,
    So I came across this little problem that I thought I could solve relatively easily, but it turned out quite messy.
    I have this array of strings and I want to find the most frequent entry of that array. Let's say I have the following array.
    apple
    apple
    kiwi
    orange
    apple
    the mode would give me apple. I thought about converting the strings into a number and then find the mode as usual.
    But if the string was too long, it seems a single number cant be used to represent it.
    Any ideas on a clean way to do this?
    Solved!
    Go to Solution.

    chembo wrote:
    This may work also
    You should probably link to the thread where this solution was first presented instead.
    Since the question was: "I have this array of strings and I want to find the most frequent entry of that array", here's is a more tailored solution to the actual question.
    Still, my more traditional approach outlined in the first answer would probably be more efficient, because it does not generate any large data structures. Try it!
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    MostFrequentStringEntry.vi ‏8 KB
    MostFrequentString.png ‏6 KB

  • Find a non-numeric character in a string

    I have a 3 strings (1) 'AB99CDEFGH0012%' (2) 'ABCDEFGH' (3) 'ABCD11'
    how do i find out a that string has non numeric characters
    Thanks

    SELECT TO_NUMBER(:String) FROM DUAL;
    is a quick way to find out :)
    A good method would be.....
    SELECT 1 FROM DUAL WHERE TRANSLATE(:String, 1234567890, '-') IS NOT NULL;
    The statement will filter out ALL numbers, leaving behind any characters, A, B, @, ~, etc...

  • Finding the 1st place character

    Hi,
    I have string and I want to check what character is present at the 1st place of the string.Can anyone tell how to do this?
    Thanks.

    Hi,
    Just use offsets.
    data: temp type string value 'abc123'.
    data: result(1) type c.
    result = temp+0(1).
    write: result.
    Regards,
    Vikranth

  • Finding the number of occurance in a string

    Hi Can someone tell me if there is a function to tell me how many times a string occurs in another string for example how many times does
    "cat"
    appear in
    "cat dog catcat dogdog cat cat"

    Praveen_Forum wrote:
    Try in the similar lines
    String name = "cat dog catcat dogdog cat cat";
    char pattern = 'c';
    int occurs = 0;
    for(int i = 0; i < name.length(); i++) {
    char next = name.charAt(i);
    if(next == pattern) {
    occurs++;
    System.out.println("Occurs " + occurs + " time(s)");
    for a string:
    String name = "cat dog catcat dogdog cat cat";
    String toFind = "cat";
    int occurs = 0;
    for(int i = 0; i < name.length()-toFind.length()+1; i++)
        if (name.substring(i, i+toFind.length()).equals(toFind))
           occurs++;
    System.out.println(occurs);

  • Help:Can not find the file in jar!

    Hello everyone:
    I build a project using Netbeans 5.0 and make a jar file with it...
    The code in the project as follows will throw an exception described that it can not find the file named datasource-config.xml
    String dataFilePath = getClass().getResource(dataFile).getPath();
    //System.out.println("filepath:"+dataFilePath);
    InputStream input = new FileInputStream(dataFilePath);
    when I run the project with the main() function as an entry it works perfectly and output:
    filepath:/C:/projects/java_project/search/build/classes/com/cn/wxjt/lucene/config/datasource-config.xml
    But when I compressed the project with jar and run it , it will show:
    filepath:file:/C:/projects/java_project/search/dist/search.jar!/com/cn/wxjt/lucene/config/datasource-config.xml
    there is a (!) between search.jar and /com/cn/wxjt...
    I dont know why I generate a ! symbol in the file path... Is it cause the exception->
    java.io.FileNotFoundException: file:\C:\projects\java_project\search\dist\search.jar!\com\cn\wxjt\lucene\config\datasource-config.xml
    If you have any idea, plz tell me.
    Thank you and best wishes to you !
    :)

    If the file you want to read is in your jar file, use
    getClass ().getResourceAsStream
    (relative_path_file_name)Hope that help,
    Jackhey jack i want to open the file as new File
    i m using this.getClass().getResource("resource/backend.xml");
    the resource is the directory inside the jar file.
    when i prints the url it shows:
    the jar file is in the WORK directory
    URL : jar:file:/home/neeraj/WORK/show.jar!/resource/backend.xml
    now when i creates new File using the url.getFile() method the file does not exist.
    although the same programs runs well when i uses the InputStream
    so plz tell me cant I create a new File from the above method????
    thanks in advance
    with regards
    neeraj

  • Get number of character within a String by number of pixels

    How can i get the number of character within a String
    by a width value...
    for example..
    i have a String = "1234567890abcdefghi.........."
    and when i give the width "10"
    i will get the String "12".
    or the number of charcter..
    or somthingggggggggggggggg
    please help..
    Shay

    i solved this...
    by doing somthing similar..
    i made a for loop on all character
    and evrey time i am get a sub string from the 0 till the loop index..
    and i am chashing the last string
    so when a sub width is greater the the requested width
    i am returning the lst cashed result
    thanks.. all..

  • How to search occurance of a character in a string

    for example in a word Mississippi, find the frequency of character S. it should be 4 as it contains four s.
    what is a code.

    Hi shri vas,
    data: result type match_result_tab,
           w_result type LINE OF  match_result_tab,
           num type c.
    FIND ALL OCCURRENCES OF 's' in 'Mississippi' results result.
    loop at result INTO w_result.
       num = num + 1.
    endloop.
    WRITE num.
    Regards,
    Seshu

Maybe you are looking for

  • HT3702 how can i remove the authorization hold from my card...

    how can i remove the authorization hold from my card

  • Problem with SQLData implementation

    Hi, I am facing a problem while retrieving an ARRAY. I am using jdbc thin driver 8.1.7.1 (patched version) to connect to the 9i Database(9.0.1.2.0). Code: public class Employee implements SQLData      public int iEmpNumber;      public String strName

  • Replacing my 2gb with a 4gb and cannot sync.

    Okay, so. I've had a 2gb forever and it finally broke. So I got a 3rd Gen 4GB. All I want to do it just put the music from my iTunes onto this stinking iPod and it won't do it. Every time I plug it in an error message with a yellow exclamation point

  • Applications folder crashes!

    When clicking Applications Folder in finder, finder will crash. I can't open Applications folders by any means. I tried to use Terminal to list all the files in Applications folder (-ls), but nothing showed up in Terminal. All the applications are in

  • MS Project - print formatting in calendar view

    Hi -  I am currently adding multiple subprojects into a master plan. When in the calendar view before printing all tasks are showing and correct. Once I go to print the print preview screen is correct. However once the 1 week calendar view is printed