Count bitpattern occurences in textstrings
Hi
I was wondering if there are any way to count the occurences of a bitpattern within a textstring using Java. If ANYONE can help me out with this one I would be eternal grateful.
For instance. If I have the text in a string named str1, I want to check this for every occurence of 11's or perhaps 00's.
I suppose so. You can always write "11+" or "00+" etc, to represent two or more contiguous occurrences of ones or zeros respectively.
If you have your binary data in the form of a String variable you can operate on it as if it were a String. So regex works, but of course you can also write your own code searching for the pattern. It's more of an algorithm problem than a Java one.
I think that from the java aspect you only need to look at the documentation of class String:http://java.sun.com/javase/6/docs/api/java/lang/String.html, so you can manipulate it according to your needs or see what you can do with the regular expressions.
Similar Messages
-
How to count a occurence of a string in file
import java.util.*;
import java.io.*;
class Count
public static void main(String args[ ] )throws Exception
FileReader fr=new FileReader("d:\\compfetch\\clean\\first.txt");
BufferedReader br=new BufferedReader(fr);
StringBuffer sb=new StringBuffer();
while((s=br.readLine())!=null)
sb.append(s);
s=sb.toString();
Vector v= new Vector();
v.addElement("job");
v.addElement("jobs");
v.addElement("career");
v.addElement("careers");
v.addElement("vacancy");
v.addElement("vacancies");
v.addElement("opportunity");
v.addElement("openings");
v.addElement("posting");
v.addElement("postings");
v.addElement("opportunities");
v.addElement("placement");
v.addElement("placements");
v.addElement("job");
v.addElement("job");
Enumeration vEnum=v.elements();
while(vEnum.hasMoreElements())
System.out.println(vEnum.nextElement());
I need to count the occurence of each string given in the vector from the text file.I have the file and the vector.How do i compare the vector and textfile ,so that i can count the occurence of eachString in the vector with the text file.The text file may contain any of the words given in the vector.If found ,a count shld be made for each string .
regards,
koelTry this code:
import java.util.*;
import java.io.*;
class Count
public static void main(String args[ ] )throws Exception
FileReader fr = new FileReader("c.c");
BufferedReader br = new BufferedReader(fr);
StringBuffer sb = new StringBuffer();
String s;
while((s=br.readLine())!=null)
sb.append(s);
s=sb.toString();
Vector v= new Vector();
v.addElement("job");
v.addElement("jobs");
v.addElement("career");
v.addElement("careers");
v.addElement("vacancy");
v.addElement("vacancies");
v.addElement("opportunity");
v.addElement("openings");
v.addElement("posting");
v.addElement("postings");
v.addElement("opportunities");
v.addElement("placement");
v.addElement("placements");
Enumeration vEnum=v.elements();
while(vEnum.hasMoreElements())
String l = (String)vEnum.nextElement();
int a = 0;
int p = s.indexOf(l,a);
int c = 0;
while (p != -1)
c = c + 1;
a = a + l.length() + p;
p = s.indexOf(l,a);
System.out.println(l+" "+c);
} -
PL/SQL - counting values' occurences in a collection - how to optimize?
Hi all,
I'm new here and working currently on my PhD thesis, using Oracle (XE) to do some data manipulation stuff.
Following is defined:
TYPE stat_col_type IS TABLE OF INTEGER;
rows_lens stat_col_type;
Using MULTISET UNION operations, I get the final rows_lens as a set of values, e.g. {1,2,3,1,1,2,2,2,3,3,3,3,3,3,3,1,1,2,1,1,4,5,6,2,2,2,3,3}.
What I need is to count the occurences of the unique values :
value of 1 : 7 occurences
value of 2 : 8 occurences
value of 3 : 10 occurences
value of 4 : 1 occurence
value of 5 : 1 occurence
value of 6 : 1 occurence
Ideally, the result should be a separate collection where the values become indexes (there are numbers, natural, unique and countable) and the number of occurences - their values :
output_col( value ) := number-of-occurences ;
Of course, I could just go through all the elements incrementing the counters in the output collection, but surely there must be a most efficient way - probably using POWERMULTISET or some kind of SUBSETS. As haven't been using /developing in/ Oracle for a longer period... it's better to ask :)
Thanks in advance for your suggestions.
Regards,
Bart
Edited by: user3698166 on 2010-01-16 13:44What I need is to count the occurences of the unique values :
Following is defined:Why don't you define in PLSQL and not in SQL?
It would be so much easier:
SQL> create type stat_col_type as table of integer
Type created.
SQL> select column_value, count (column_value) cnt
from table (
stat_col_type (1,
2,
3,
1,
1,
2,
2,
2,
3,
3,
3,
3,
3,
3,
3,
1,
1,
2,
1,
1,
4,
5,
6,
2,
2,
2,
3,
3
group by column_value
order by column_value
COLUMN_VALUE CNT
1 7
2 8
3 10
4 1
5 1
6 1
6 rows selected.
SQL> drop type stat_col_type
Type dropped. -
Count the occurences of a specific combination of chars
Hi there
I want to count the occurences of a specific combination of characteristic in a query.
Example count the occurences of combination CHAR1 CHAR2 CHAR3
CHAR1 CHAR2 CHAR3 Counter
A BB CCC 1
A BB CCC 1
A BB DDD 1
A SS DDD 1
Query Result should be
CHAR3 Count
CCC 1
DDD 2
In the HowTo Paper: Count the occurrences of a
characteristic relative to one or
more other characteristics it is only a solution with one characteristic but not with a combination of chars.
I don't know if this possible, because I think it is necessary to do a expeption aggregation based on several chars.
Anyone an Idea?
Thanks a lot in advance
JoeJoe,
I think in your case it is the case of multiple characteristics and I think the straight way is to do with exception aggregation.
See the below link
http://help.sap.com/saphelp_nw04/helpdata/en/d2/e0173f5ff48443e10000000a114084/frameset.htm
See the below link for some more discussions using formulas which may help you to arrive a decision.
Count elements in a characteristic
Regs
Gopi. -
Count the occurence of a character in a string
Post Author: halfpat
CA Forum: Formula
Hello to everyone,
I use CR 8,0. Is anyone can tell me if this is possible:
I have a string "12345-C-1 23456-C-2 34567-C-4", how can I count the occurence of the "C" character in this string ?Is the InStr function can help me to do this ?
I appreciate any suggestion,
Thanks.Post Author: bettername
CA Forum: Formula
How about measuring the length of the string, and subtracting the length of the same string where C is replaced with <nothing>?
len("12345-C-1 23456-C-2 34567-C-4") - len(replace("12345-C-1 23456-C-2 34567-C-4" , "C", "")) -
Count of occurences of a string senetence in 9i?
Hi All,
Is there an easy way using SQL to count the number of occrences of a string in a sentence? Dont want to use pl/sql if i can help it, maybe im missing an easy function?. Im using 9i rel2.
eg find the count of ':' in the below string
a:b:c:d: should return 4. (the separtor being : included on the end)
a:b: should return 2
and so on?
Kind Regards
SatnamSQL> SELECT a-LENGTH(REPLACE(SUBSTR(p,1,a),':',''))
2 FROM
3 (SELECT INSTR('a:b:c:d:e:',':',-1,1) a
4 ,'a:b:c:d:e:' p
5 FROM dual);
A-LENGTH(REPLACE(SUBSTR(P,1,A),':',''))
5Khurram -
How to count number of occurences of a character in a string
I want to get the count of occurences of a character within a string. Is there any function for this or should i go for a PLSQL.
For example is the sting is "occurences" & if i search for character "c", the answer should be 3.
Regards,
Sunil.SQL> select length('occurence') - length(replace('occurence','c')) from dual;
LENGTH('OCCURENCE')-LENGTH(REPLACE('OCCURENCE','C'))
3 -
How to Count a Characteristic Occurence?
Morning,
I have Assembly(Material) being displayed as a Row item in my query. My need is to count the number of rows for Assembly in the query. I referred to "How to Count" doc, but that counts every occurence of assembly. Whereas, I need to count an Assembly just once.
Can somebody help me on this?
Thanks.Vijay,
Here is how it is desired:
Plant Assembly Count
7835 711712101 1
< > 711712103 1
< > 711712111 1
< > 711712401 1
< > 711713101 1
Can you explain how I can do with this? -
Hello Experts,
I have the following query related to counting occurences of a particular characteristic related to the Calendar month
1) When I choose the option "Average of all values" within exception aggregation for the calculated keyfigure that I am using for the count, it counts all the values including duplicates .i.e. if the charcteristic has repeated occurences for a given month, then it is counted distinct occurence. However, in this case it is not showing me "0" for no occurence but just displaying a blank
2) But when I choose the option "Counting all values" within exception aggregation for the calculated keyfigure that I am using for the count, it does provides me "0" for no occurences but it counts the repeated value as single occurence
How can I get around this? I mean to get repeated values to be counted as separate occurences and also being able to show "0" for no occurence.
Any help will be appreciated
Thanks,
RishiHi ,
Please use exception aggregation as you already did with count all values.
But you need to select a specific reference chars to select the unique count.Plant or the Month can be a option.
In BI7.0 U have concept of nested aggregation:
Create a CKF1 with reference to one Char. and craete another CKF2 using the earlier CKF1 and put again a reference on some other char.
that will solve the problem.
Please take care of the selection of Char while doing reference char. -
Counting the number of occurences in a table column
Hi All
I have a table with a column that contains approx. 5000 6-digit codes. A number of these codes are duplicted in the column, and I want to count the number of occurences of each code. The column looks a bit like -
WCID
940042
920012
940652
940199
188949
155146
155196
174196
152148
151281
196209
174015
182163
195465
195318
182008
189589
150675
There can be mulitple instances of each WCID and I need to count the number of instances of each. I also have access to another table that also has a column of each WCID, but only once - ie no multiple instances. The second table is identical except that there are only single instances of each WCID.
I thought I could either loop through on the table to be counted, from 100000 to 999999 and count each occurence that way, but it would be very inefficient. The other way I thought would be to perhaps select a WCID from the unique table, count the occurence of that, select the next WCID from the unique table, count that and so on, however I'm not sure how to do it in PL/SQL. Perhaps select the WCID from the unique table into a cursor, loop through that and compare it with the original table and count the instances?
I hope this makes some sense, any help would be really appreciated
Thanks
BillHi, Bill,
That sounds like a job for GROUP BY:
SELECT wcid
, COUNT (*) AS num_found
FROM table_x
GROUP BY wcid
ORDER BY wcid
I hope that answers your question.
If not, post CREATE TABLE and INSERT statements for a little sample data, and the results you want from that data. -
I don't know nothing about NI image DAQ, I'm new to this, I'm a Labwindows/CVI programmer and recently a client asked me if its possible to count cells occurences in an image. Before investing money in such system (seems to be very expensive) I would like to know if NI VISION functions are powerfull enough to count occurences of a human cell in an image ?
Thank you,The short answer to your question is yes and there are similar examples on the IMAQ Vision demonstration CD. I would suggest you try and organize a demo from your local NI office.
Application Note 107 gives a good tutorial on this topic and you can get access to it at the following link:
http://zone.ni.com/devzone/conceptd.nsf/webmain/1D977AE5ED42CB0C86256869007215CC?opendocument&node=DZ52495_US
As far as support for LabWindows/CVI is concerned, you may see a lot more "traffic" regarding LabVIEW on Developer Zone, but rest assured the capability of the CVI version of IMAQ Vision is virtually identical and there should be enough help either direct from NI or through Developer Zone to help with your application.
With regards to questions about cost, t
he cost of the application will have to be considered versus the benefits of introducing an autonomous inspection system. Your customer may find that the increases in throughput i.e. number of samples/images per hour that can be inspected or the reliability of the results produced (most people will strive towards a 100% inspection imaging application) will offset the initial development costs. This is particularly true if your customer is currently manually inspecting the samples (for example under a microscope).
Jeremy -
Hello,
I have a count requirement that i havent been able to solve by searching sdn. Maybe someone can help.
I have a query built on a multiprovider that points to two basic cubes. The basic cubes do not contain a count key figure. The first two columns of my query are characteristics. My requirement is to count the occurences of the combination of the first two column (characteristics). I am looking for a way to do this in the query so i do not have to reload the cubes as they have large volumes of data. All the suggestions i have been able to find on sdn seem to be only for counting a single characteristic. Is there a way to count the combination of two?
Regards,
TMSHi Create a count using the formula or calculated ket figure for the count unique id like client id for your infocube.
so you will have a count for each row now. place this count object in your column.
now select the two char or the group whatever you want a count in your row.
select query properties and select the display tab and make sure the option - hide repeated key values is selected (normally by default it is selected). Then select each of the char in rows and in free char and set the option under display tab result rows - always suppress.
Execute the query now. you will get the list of char and their count. sort the count by descending to get the most duplicate entries by their highest number on top in the count coulmn.
you can also ignore the rows which donot have a duplicate i.e count more than 1 by creating a new condintion on the count key figure > 1 and restricting the condition by only the group of char you have given in the column. so that you can also do a drill down by free char in your query and it will only show the duplicates group.
Hope it helps.
regards,
Siva -
Mapping Help required in Node count
Hi Friends,
i need to count the number of occurences of source node. i'm able to count the occurences.
but i have some problem with this node. Source node happens only some times.
Source node.
<Event>
type- attribute
<Date>20092509</Date>
</Event>
Sometimes Event tag comes as </Event> without any type value then i need to pass " 0 " value.
Cases :
1. if empty Event tag happens then need to Pass "0"
2. <Event>
type
<Date></Date> in this case also need to pass 0.
3. <Event>
type "Order"
<Date>20092509</Date>
</Event>
<Event>
type "Delivery"
<Date>20092509</Date>
</Event>
in this case need to pass node count as "2"
please suggest me on this;
Regards,
DeepsHi sandeep,
Map like this..
Date--\
then
Date---->NotEquals---->if -----\
Constant[]/ \
else \
Constant[0]/ \
then
Date----->Exisists---->if-------- ----->Output
else
Constant[0]/
I tested this...
Working Fine...
Thanks. -
Counter column in the Receiver file
Hi All,
My requirement -->
Souce is IDOC and target is a file.
In the Receiver file there is one column counter which will indicate the counter for each line...
So the Receiver file should be like this
FHEAD,0001
THEAD,00002,00001,20081103
TDETL,0003,0001,A,777,23456789
TDETL,0004,0002,M,881,45333333
TTAIL,0005
THEAD,0006,00002,20081103
TDETL,0007,0001,A,777,23456789
TDETL,0008,0002,M,881,45333333
TDETL,0009,0003,M,381,4533677
TTAIL,0010
FTAIL,0011
The problem is when i map with the source and use counter for the second column, i am getting the counters different, this is due to the condition on the node level, because if 10 idocs come the file may need only 5 based on condition. but since source occurence is 10 the counter cannot give correct values in the file as required,
Please suggest the best way to handle this..
Regards,
Sridhar ReddyHi,
>>this is due to the condition on the node level, because if 10 idocs come the file may need only 5 based on condition. but since source occurence is 10 the counter cannot give correct values in the file as required,
As far as i understand the question, you need the 5 Idocs based on condition and then you want to give the counter 1 to 5. Right ?
If this is the case just use one more additional parameter for counting the occurence when some Idoc come just increment it.
Like if you are using X variable for counting Idocs earlier n i think you are using that variable only for assigning count for filtered Idocs. or may be you are checking some condition and thats why that output for count is coming wrong. Use another variable and then increment that variable and assign that variable value to desired place.
Regards
Aashish Sinha -
Function in finding the count of ocurrances of an XML tag in j developer
Hi All,
I need to find the count of an xml tag that appears mutliple times in an xml payload.
I did not find any function in bpel doing this.I am using j developer version 11.1.1.5.0 and SOA Composite editor version 11.1.1.5.0.01.74
Is there any function in Bpel that gives as the count of occurence of an element in a payload?
Kindy suggest me on this.The below function is used inside XSLT to count the nodeset
count(inputNodeSet as node-set)
Returns the number of nodes in inputNodeSet.
Thanks,
Vijay
Maybe you are looking for
-
I have an Iphone 4s and i have two reocurring problems. So my first problem was after I had synced all my music most of the new songs and some old that never had a problem before had a red circle with a red square inside of it. I've gotten rid of it
-
Why do I keep getting Error 1000 When I run Abort VI Method?
Need to know how to get this to work
-
Help in using JSP: Urgent As Project dues soon
Hello Guys, i am new here. I got some problems using jsp. My main project is about a webpage where there is login and password for users. But, I can GO to a certain JSP page without LOGINING in. For example, i got a jsp page for customer to buy and s
-
2 tracks not being included with rest of an album
I have 1 x album which contains 17 tracks. The album appears twice in my iTunes library: 1 with 15 tracks and 1 with 2 tracks. I've been through and made sure all the names etc are correct (no spaces at the end of a name/title or anything), but whate
-
When making a soft proof copy it brings any additional adjustment almost to a halt in LR5. Windows 7 64bit, Quad core processer, 12gig ram. Is this normal or do ii need to change a setting? PS Same when working on a vitural raw copy.