473,836 Members | 1,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String function (counting string within a string)

Does anyone know of a string function in Access that will allow me to
count the number of instances one string occurs within another? Or if
there is some sort of word count function? If there is, I'm not aware
of it. I've tried the following unsuccessfully ...

SELECT *, (Len([myfield])-Len(Replace([myfield],'
what_im_looking _to_count','')) )/(Len(' what_im_looking _to_count')) AS
KeywordFoundCou ntFROM tblYourTable;

That'll find how many times the phrase what_im_looking _to_count occurs
within the field called 'myfield'

Thanks,

Ralph Noble
ra*********@hot mail.com
Nov 13 '05 #1
4 3495
What error do you get trying to use that query?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Ralph Noble" <ra*********@ho tmail.com> wrote in message
news:ed******** *************** ***@posting.goo gle.com...
Does anyone know of a string function in Access that will allow me to
count the number of instances one string occurs within another? Or if
there is some sort of word count function? If there is, I'm not aware
of it. I've tried the following unsuccessfully ...

SELECT *, (Len([myfield])-Len(Replace([myfield],'
what_im_looking _to_count','')) )/(Len(' what_im_looking _to_count')) AS
KeywordFoundCou ntFROM tblYourTable;

That'll find how many times the phrase what_im_looking _to_count occurs
within the field called 'myfield'

Thanks,

Ralph Noble
ra*********@hot mail.com

Nov 13 '05 #2
"Ralph Noble" <ra*********@ho tmail.com> wrote in message
news:ed******** *************** ***@posting.goo gle.com...
Does anyone know of a string function in Access that will allow me to
count the number of instances one string occurs within another? Or if
there is some sort of word count function? If there is, I'm not aware
of it. I've tried the following unsuccessfully ...

SELECT *, (Len([myfield])-Len(Replace([myfield],'
what_im_looking _to_count','')) )/(Len(' what_im_looking _to_count')) AS
KeywordFoundCou ntFROM tblYourTable;

That'll find how many times the phrase what_im_looking _to_count occurs
within the field called 'myfield'

Thanks,

Ralph Noble
ra*********@hot mail.com


In what sense was your attempt to use this function unsuccesful? The
function really does count the occurences of one string within another. For
example, if you had tblMyTable with fields MyID and MyText and wanted to
count how many times the word 'pen' occurs in that field:

SELECT tblMyTable.MyID , tblMyTable.MyTe xt,
(Len(MyText)-Len(Replace(MyT ext,'pen','')))/(Len('pen')) AS
KeywordFoundCou nt
FROM tblMyTable

I can see some problems you might encounter, such as when counting the
occurences of the word "pen" in the sentence "I spent 4 dollars on that
pen." The function returns 2 (not 1) because "pen" occurs within the word
"spent"

Nov 13 '05 #3
"Ralph Noble" <ra*********@ho tmail.com> wrote in message
news:ed******** *************** ***@posting.goo gle.com...
Does anyone know of a string function in Access that will allow me to
count the number of instances one string occurs within another?


Try this:
----------------------------------------
Public Function AAA(StringToSea rchIn As String, StringToSearchF or As String)
As Integer
Dim i As Integer, k As Integer, h As Integer
For i = 1 To Len(StringToSea rchIn)
h = InStr(i, StringToSearchI n, StringToSearchF or)
If h Then
k = k + 1
h = h + 1
i = h
End If
Next
AAA = k
End Function
-----------------------------------------

Ciao
Bruno
Nov 13 '05 #4
"Ralph Noble" <ra*********@ho tmail.com> wrote in message
news:ed******** *************** ***@posting.goo gle.com...
Does anyone know of a string function in Access that will allow me to
count the number of instances one string occurs within another? Or if
there is some sort of word count function? If there is, I'm not aware
of it. I've tried the following unsuccessfully ...

SELECT *, (Len([myfield])-Len(Replace([myfield],'
what_im_looking _to_count','')) )/(Len(' what_im_looking _to_count')) AS
KeywordFoundCou ntFROM tblYourTable;

That'll find how many times the phrase what_im_looking _to_count occurs
within the field called 'myfield'

Thanks,

Ralph Noble
ra*********@hot mail.com


In what sense was your attempt to use this function unsuccesful? The
function really does count the occurences of one string within another. For
example, if you had tblMyTable with fields MyID and MyText and wanted to
count how many times the word 'pen' occurs in that field:

SELECT tblMyTable.MyID , tblMyTable.MyTe xt,
(Len(MyText)-Len(Replace(MyT ext,'pen','')))/(Len('pen')) AS
KeywordFoundCou nt
FROM tblMyTable

I can see some problems you might encounter, such as when counting the
occurences of the word "pen" in the sentence "I spent 4 dollars on that
pen." The function returns 2 (not 1) because "pen" occurs within the word
"spent"


Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1334
by: Igor2004 | last post by:
Ladies and Gentlemen, I would like to offer you the following string functions Transact-SQL GETWORDCOUNT() Counts the words in a string GETWORDNUM() Returns a specified word from a string AT() Returns the beginning numeric position of the first occurrence of a character expression within another character expression, counting from the leftmost character RAT() Returns the numeric position of the last (rightmost) occurrence of a
0
1313
by: Igor Nikiforov | last post by:
Ladies and Gentlemen, I would like to offer you the following string functions Transact-SQL GETWORDCOUNT() Counts the words in a string GETWORDNUM() Returns a specified word from a string AT() Returns the beginning numeric position of the first occurrence of a character expression within another character expression, counting from the leftmost character RAT() Returns the numeric position of the last (rightmost) occurrence of a
14
2310
by: Mike N. | last post by:
Hello: I have a form that contains a multiple-select field that has 12 options in it. I would like the user to be able to select UP TO FOUR of those options. If they select more than four, I would like to alert them of the error. To do this, I figure that counting commas would be the easiest method (i.e., IF commas > 3 THEN alert user). NOTE: I have an existing "validateForm" function for this form and I'd like to add this IF-THEN...
32
14932
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
9
7447
by: Divick | last post by:
Hi all, I have a problem related to std::string class. Is it ok to assign a global string variable to a local string object as shown below? I am trying to print the address of local string buffer and then I print the address of global string buffer and come out to be same, but I assume that as soon as func method has returned that temporaryString string must have been deleted and thus the buffer that it might be holding might get...
24
2333
by: Derek Hart | last post by:
Is there an efficient line of code to count the number of instances of one string within another. If I have the sentence: "I want to go to the park, and then go home." It would give me a count of 2 for the word "go" Derek
4
9352
by: John | last post by:
1. Is there an easy function in VB to count for instance the number of A's in a string? 2. Is there an easy funtion in VB to pull all characters out of a string into an array? (I tried the split function but that needs a separator.) Thanks, john
3
1353
by: Jason Huang | last post by:
Hi, In C#, how do I retrieve a special sub string within a big string? e.g., the "...fdsajk...ABC123...fdfdskafdl... ..." string has 5000 characters, and I want to retrieve the string "123" which is right after the "ABC", given that counting the index of the "123" is nearly impossible. Thanks for help.
4
2806
by: sandvet03 | last post by:
I am trying to expand on a earlier program for counting subs and now i am trying to replace substrings within a given string. For example if the main string was "The cat in the hat" i am trying to find a chosen substring lets say "cat" and then replace it with a difrent inputed substring say "dog". Tried to get as far as i could on my own but need some help, sugestions, snippets or guidence. # include<stdio.h> # include<math.h> #...
0
10844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10546
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10590
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9374
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7791
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6979
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4449
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3113
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.