Counting a particular word in a string
Hi All,
Have a query to find the occurence of a particular word in a string using a query.
ex: str := 'a,b,a,c,d'
search_str := 'a'
=> need to get the number of times 'a' is getting repeated in the string str.
output: 2
Hoping for the best support as always.
Edited by: Aparna16 on Jul 17, 2012 5:55 AM
Edited by: Aparna16 on Jul 17, 2012 5:56 AM
SQL> ed
Wrote file afiedt.buf
1 with sample_data as
2 (
3 select 'aaa,abcdd,abc,abc,asdasd' cola, 'abc' matchCol from dual union all
4 select 'a,b,a,c,d', 'a' from dual union all
5 select 'a,b,a,c,d', 'e' from dual union all
6 select 'aaa,abcdd,abc,abc,asdasd,abc', 'ab' from dual union all
7 select 'aaa,abcdd,abc,abc,asdasd,abc', 'abc' from dual
8 )
9 select cola, matchcol, length(cola||',') - length(replace(cola||',',matchcol||',',substr(matchcol,2)||',')) cnt
10* from sample_data
SQL> /
COLA MAT CNT
aaa,abcdd,abc,abc,asdasd abc 2
a,b,a,c,d a 2
a,b,a,c,d e 0
aaa,abcdd,abc,abc,asdasd,abc ab 0
aaa,abcdd,abc,abc,asdasd,abc abc 3
Similar Messages
-
How to search for a particular word in a string?
How to search for a particular word in a string?
thanks for your help....This works fine.
public class Foo {
public static void main(String[] args) {
String s = "Now is the time for all good...";
String s2 = "the time";
System.out.println(s.contains(s2));
System.out.println(s.contains("for al"));
System.out.println(s.contains("not here"));
}output:true
true
falseYou must have something else wrong in your code.
JJ -
How to count number of words in a string?
Is it only possible by counting the number of white spaces appearing in the string?
Of course that also depends upon how accurate you need to be and what the string contains. It is completely possible that there might be a line break which doesn't have a trailing or leading space.
Like that.
In that case Flash's representation of the string is likely "...space.\n\nLike that.." In chich case "space.\n\nLike" will be a word.
Also if you split on space and there are places where there are two spaces in a row you could inflate your number. So somthing that changes newlines (and returns) to spaces, then removes any multiple spaces in a row, and finally does the split/count thing would be more accurate.
But it all depends upon what you need. -
How i can count the number of words in a string?
hi, i want to know how to count the number of words in a string
e.g. java is a very powerful computer language.
i will get 7 words.
thanks in advance..Jverd, this has actually been answered, but due to an
attack of goldie-itis, all the answers were hosed.
The OP did get an answer, though.Yeah, I know. I just didn't know if he saw the answer before it went away. -
Count the ocurrences of a particular word in the log file of content server
Hi all,
How can we achieve this.
Thanks,
Chelyping.sumit wrote:
Hi
If I have a paragraph in a string, and have to find the occurrences of a particular word. How can I do that.
for example if i have this paragraph in a String, and I have to find the occurrence of the word "the", how can I do that.
...ping.sumit, you've been a (fairly) active member on these forums for almost a year now. Do you really have no idea how to begin solving this problem? -
Counting times a word appears in document
I am trying to read from a file and count how many times a word appears in that document.
For example if i had a list of names
Daniel Fowler
Joe Mahogony
Daniel Peterson
Chris Sim
How would you count the amount of people named Daniel and display it?
I am currently using findInLine"Daniel" but when ran no luck.
Any ideas?danieltnbaker wrote:
deepak,
the bufferedreader reads content from the file yes?
but what method would i use to count the amount of a word in that file?
finInLine finds the word but cannot turn that into an integer. any other methods?first of all the code I had posted in my previous post should work and it uses the Scanner to read the file.
If you want to use the FileReader approach the within the code that actually reads the file line by line, you can use the String.indexOf method (as suggested by nclow) to check if a particular word is present in that line of the file. IF it is there you increment a counter.
int counter = 0;
// Read through the entire file
String currentLineFromFile = bufferedReader.readLine(); // throws IOException
while(currentLineFromFile != null)
// Add a carriage return (line break) to preserve the file formatting.
textFromFile.append(carriageReturn + currentLineFromFile);
currentLineFromFile = bufferedReader.readLine(); // throws IOException
if (currentLineFromFile.indexOf("Daniel") != -1)
counter++
System.out.println("No of occurances- " + counter);
}hope this helps
[email protected]
Edited by: deepak_1your.com on 16-Apr-2008 14:18 -
How to Count number of words in a file....
Hi Experts,
I have uploaded the text file, from the application server, like this:
call function 'GUI_UPLOAD'
exporting
filename = LV_ip_FILENAME
tables
data_tab = LT_FILETABLE.
The text file contains some number character words.... like "sap labs india..... "
Now, I wanted to count number of words in an internal table LT_FILETABLE.... can anybody help me?Hi,
Special Characters in Regular Expressions
The following tables summarize the special characters in regular expressions:
Escape character
Special character Meaning
Escape character for special characters
Special character for single character strings
Special character Meaning
. Placeholder for any single character
C Placeholder for any single character
d Placeholder for any single digit
D Placeholder for any character other than a digit
l Placeholder for any lower-case letter
L Placeholder for any character other than a lower-case letter
s Placeholder for a blank character
S Placeholder for any character other than a blank character
u Placeholder for any upper-case letter
U Placeholder for any character other than an upper-case letter
w Placeholder for any alphanumeric character including _
W Placeholder for any non-alphanumeric character except for _
[ ] Definition of a value set for single characters
[^ ] Negation of a value set for single characters
[ - ] Definition of a range in a value set for single characters
[ [:alnum:] ] Description of all alphanumeric characters in a value set
[ [:alpha:] ] Description of all letters in a value set
[ [:blank:] ] Description for blank characters and horizontal tabulators in a value set
[ [:cntrl:] ] Description of all control characters in a value set
[ [:digit:] ] Description of all digits in a value set
[ [:graph:] ] Description of all graphic special characters in a value set
[ [:lower:] ] Description of all lower-case letters in a value set
[ [:print:] ] Description of all displayable characters in a value set
[ [:punct:] ] Description of all punctuation characters in a value set
[ [:space:] ] Description of all blank characters, tabulators, and carriage feeds in a value set
[ [:unicode:] ] Description of all Unicode characters in a value set with a code larger than 255
[ [:upper:] ] Description of all upper-case letters in a value set
[ [:word:] ] Description of all alphanumeric characters in a value set, including _
[ [:xdigit:] ] Description of all hexadecimal digits in a value set
a f
v Diverse platform-specific control characters
[..] Reserved for later enhancements
[==] Reserved for later enhancements
u2192 More
Special characters for character string patterns
Special character Meaning
Concatenation of n single characters
{n,m} Concatenation of at least n and a maximum of m single characters
{n,m}? Reserved for later enhancements
? One or no single characters
Concatenation of any number of single characters including 'no characters'
*? Reserved for later enhancements
+ Concatenation of any number of single characters excluding 'no characters'
+? Reserved for later enhancements
| Linking of two alternative expressions
( ) Definition of subgroups with registration
(?: ) Definition of subgroups without registration
1, 2, 3 ... Placeholder for the register of subgroups
Q ... E Definition of a string of literal characters
(? ... ) Reserved for later enhancements
for more details please refer the following,
[http://help.sap.com/abapdocu_70/en/ABENREGEX_SYNTAX_SIGNS.htm]
[http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/902ce392-dfce-2d10-4ba9-b4f777843182?QuickLink=index&overridelayout=true]
Thanks,
Renuka S. -
How to find a particular word in a textArea
can anyone tell me how to search for a particular words in a textArea that contains hundreds of sentences by ignoring the space. for example i want to search for the word "book"
so far i can detect the words with the space included
if the sentence goes like this
"hello_this_isMy book" the searched words can be found
but if the sentece goes like this
"Hello_this_isMy_booK " the searched words can not be found
.. can anyone pls tell me how to do this.I though you didn't WANT it to be found, your original post isn't clear
public boolean searchWord(String text, String word){
boolean wordFound = false;
StringTokenizer stkn = new StringTokenizer(text," ");
while(stkn.hasMoreTokens() ){
String tmp = stkn.nextToken;
if(tmp.equals(word)) wordFound = true;
stkn = new StringTokenizer(text,???); // fill in the -???- yourself
while(stkn.hasMoreTokens() ){
String tmp = stkn.nextToken;
if(tmp.equals(word)) wordFound = true;
return wordFound;
} -
Finding the no. of occurence of a particular word in a paragraph.
Hi
If I have a paragraph in a string, and have to find the occurrences of a particular word. How can I do that.
for example if i have this paragraph in a String, and I have to find the occurrence of the word "the", how can I do that.
Paragraph: Desperate to avoid another market-crushing defeat, House leaders won key converts Thursday to the $700 billion financial industry bailout on the eve of a make-or-break second vote.President Bush and congressional leaders lobbied furiously for the dozen or so supporters they'd need to reverse Monday's stunning setback and approve a massive rescue plan designed to stave off national economic disaster.
"A lot of people are watching," Bush pointed out ? as if lawmakers needed reminding ? and he argued from the White House that the measure was the best chance to calm unnerved financial markets and ease a spreading credit crunch. Anything but reassured, investors sent the Dow Jones industrials plunging another 348 points lower.
ANY IDEA GUYS???ping.sumit wrote:
Hi
If I have a paragraph in a string, and have to find the occurrences of a particular word. How can I do that.
for example if i have this paragraph in a String, and I have to find the occurrence of the word "the", how can I do that.
...ping.sumit, you've been a (fairly) active member on these forums for almost a year now. Do you really have no idea how to begin solving this problem? -
TextEdit Applescript help counter of certain words
I have tried to modify a script that finds and replaces text. My goal is to count the instances the script finds a word, say "love", and spit out the number of instances that the word "love" appears in the document so I can use it for another subroutine. Any help is appreciated.
I have this as guideline but it seems it does not work.
tell application "TextEdit"
set myCountSign to text of document 1
set myCount to count myCountSign
repeat with this_word in myCountSign
if (this_word as string) is "love" then
set myCount to myCount + 1
end if
end repeat
myCount
end tellThe most obvious problem with your script is the line:
repeat with this_word in myCountSign
This looks at myCountSign (a block of text) and iterates through it assigning each text object to this_word.
The problem is that by default each 'text object' is each character therefore you're comparing each character in the text to the string 'love' which will never, ever match. Even if the word exists you'd be performing a character-by-character comparison.
The simplest fix is to tell AppleScript to look at the words in the text, which is done simply by:
repeat with this_word in (words of myCountSign)
(note you might also need to do this for 'set myCount to count myCountSign' since this will return the character count, not the word count)
There are other, more efficient ways (such as via text item delimiters):
tell application "TextEdit"
set myCountSign to text of document 1
set wordCount to (count words of myCountSign)
set {oldtids, my text item delimiters} to {my text item delimiters, "love"}
log set keywordCount to (count text items of myCountSign) -1
set my text item delimiters to oldtids
display dialog "The document has " & wordCount & " words and " & keywordCount & " occurrences of the word 'love'"
end tell
The text item delimiters approach works by breaking the text into chunks at each occurrence of the delimiter (in this case, the string 'love'). Then all you have to do is count the number of chunks (minus 1) which is a lot quicker than counting all the words, especially for large documents. -
Program to count number of words
I need some help with writing a program that counts the number of words in a file. Can anyone help me?
I would try:
read line
save line to a string
use split(" ") method from String to get each word
into a String[]
then put each entry in the array into a list
repeat for all lines
get size of listThat will only work for small-ish files. I would recommend using indexOf() until EOF is reached. You would need logic to ignore consecutive spaces and the like, but it should be both significantly smaller in memory footprint and faster in execution speed.
- Saish -
Returning Count of Matching Words Rather than Score
I'm using the SCORE function that will return a number representing the relevance of the matching search result; however, what the users really want is a COUNT of the number of search results returned within the document. For a search on the word "cat" this would return the number of times the word "cat" appears in the document. Ideally, if the user searched for "(dog and cat) within sentence", the COUNT would be of the number of times both dog and cat occur within sentences in the document; however, it would be acceptable to count the number of matching words in the document individually.
Does Oracle Text have any way to return this COUNT directly within the results Oracle Text query? I can use a CTX_DOC.MARKUP call to mark the document up and the count the instances of the markup strings, but that's going to be a lot slower than if Oracle supports this out-of-the-box on the original query syntax.Yes (in 10g onwards), you need to use a query template with <score algorithm="COUNT"/>
See here:
http://www.oracle.com/technology/products/text/x/10g_tech_overview.html#qry_cscore
Though the example there is a bit confusing since it has algorithm="SCORE" - the option for normal scoring. -
Anyway to highlight a particular word in text?
I'm trying to implement some necessary features using htmlText (http://livedocs.adobe.com/flex/3/html/help.html?content=textcontrols_04.html). One thing I need to do is highlight a particular word in a sentence. Something along the lines of
This is a sentence with a <highlight> highlighted </highlight> word.
None of the tags in the aforementioned list seem to be able to be able to do anything like this. I was hoping for a backgroundColor attribute in the font tag, or something. I've also looked at the CSS capabilities, etc... and simply using setStyle("backgroundColor" ...) wouldn't do any good, as I need to highlight only one word.
It seems we'll just have to find another way to emphasize the text in question, but before I abandon all hope, am I missing anything?I think you already know this, but you can change the color of the text with <font color=""> and/or make it bold with <b>, and I think you can make it italic with <i> or <em>.
Like I said, I think you already knew that but thought I'd mention it.
You could use the drawing API to draw a rectangle under the word, but with different fonts and font sizes that would be difficult to get right and consistent.
If this post answered your question or helped, please mark it as such. -
Hello,
I'm designing my own website and want to know how to change the background color of a particular word without changing the background color of the rest of the text in a textbox. If i can't do this, how can I create a Table, similar to Excel with iWeb?
Thank you very much!
Roger.If i can't do this, how can I create a Table, similar to Excel with iWeb?
Read this :
Create and add a TABLE in iWeb »
More about a TABLE in iWeb »
Sample 1
Sample 2 -
How to find a particular word in a file using java
Program how to find a particular word in a file
SirivaniG wrote:
Program how to find a particular word in a fileOkay, I finished it. Now what?
Maybe you are looking for
-
ITunes 7.3 failed back up data DVD burn had error code 261(0x00000105).
Just bought a bunch of new songs and went to back them up in iTunes 7.3 and I keep getting error code 261(0x00000105). Any ideas? Did not have this problem in prior versions. Brner works fine with other programs. Thanks! Home Brew Windows XP Pro
-
How can i lock in my home page and not have it chang after shutdown
every time i shut down and restart it goes to a page that is not my home page witch is yahoo and it wont lock in
-
That pretty much says it all in the question.. Thanks
-
Usage of logical name, logical path name, physical name of a file
Hi all, I have to write to a file on the application server. I had been given the logical name, logical path name and physical name. Suggest how to use these parameters and get the path where to store the file. Thanks & Regards, Kasinath.
-
Fluidsynth and systemd integration
I've followed the directions to enable fluidsynth ALSA daemon mode via systemd integration, but the instructions of this page https://wiki.archlinux.org/index.php/FluidSynth don't seem to work. It seems to me that systemd tries to run the service as