A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Count for multiple occurrence of an expression in a string



 
 
Thread Tools Display Modes
  #1  
Old June 25th, 2006, 07:56 AM posted to microsoft.public.access.tablesdbdesign
external usenet poster
 
Posts: n/a
Default Count for multiple occurrence of an expression in a string

I want to count number of '.' (dots) in an expression e,g. asd.rty.de.com
(answer = 3 dots at positions 4,8,11 respectively) . Instr functions gives
only the first occurrence.
Any help is appreciated
Thanks
Anupam
  #2  
Old June 25th, 2006, 08:51 AM posted to microsoft.public.access.tablesdbdesign
external usenet poster
 
Posts: n/a
Default Count for multiple occurrence of an expression in a string

What comes redily to mind is a function that accepts two arguments:
the string to analyze and the comparison character. Look in Help for
Mid. The function would return an number of times the comparison
character was found in the string as an integer.

HTH
--
-Larry-
--

"chinky" wrote in message
...
I want to count number of '.' (dots) in an expression e,g.

asd.rty.de.com
(answer = 3 dots at positions 4,8,11 respectively) . Instr functions

gives
only the first occurrence.
Any help is appreciated
Thanks
Anupam



  #3  
Old June 25th, 2006, 09:05 AM posted to microsoft.public.access.tablesdbdesign
external usenet poster
 
Posts: n/a
Default Count for multiple occurrence of an expression in a string

How about:

UBound(Split("asd.rty.de.com", "."))

Assumes Access 2000 or later.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"chinky" wrote in message
...
I want to count number of '.' (dots) in an expression e,g. asd.rty.de.com
(answer = 3 dots at positions 4,8,11 respectively) . Instr functions gives
only the first occurrence.
Any help is appreciated
Thanks
Anupam



  #4  
Old June 25th, 2006, 03:06 PM posted to microsoft.public.access.tablesdbdesign
external usenet poster
 
Posts: n/a
Default Count for multiple occurrence of an expression in a string


Thanks for the response.
I am using Windows 2003, but these functions are not available. Do I need to
install something ?

"Allen Browne" wrote:

How about:

UBound(Split("asd.rty.de.com", "."))

Assumes Access 2000 or later.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"chinky" wrote in message
...
I want to count number of '.' (dots) in an expression e,g. asd.rty.de.com
(answer = 3 dots at positions 4,8,11 respectively) . Instr functions gives
only the first occurrence.
Any help is appreciated
Thanks
Anupam




  #5  
Old June 25th, 2006, 03:07 PM posted to microsoft.public.access.tablesdbdesign
external usenet poster
 
Posts: n/a
Default Count for multiple occurrence of an expression in a string

Thanks for your response. I will look into it.

"Larry Daugherty" wrote:

What comes redily to mind is a function that accepts two arguments:
the string to analyze and the comparison character. Look in Help for
Mid. The function would return an number of times the comparison
character was found in the string as an integer.

HTH
--
-Larry-
--

"chinky" wrote in message
...
I want to count number of '.' (dots) in an expression e,g.

asd.rty.de.com
(answer = 3 dots at positions 4,8,11 respectively) . Instr functions

gives
only the first occurrence.
Any help is appreciated
Thanks
Anupam




  #6  
Old June 25th, 2006, 03:27 PM posted to microsoft.public.access.tablesdbdesign
external usenet poster
 
Posts: n/a
Default Count for multiple occurrence of an expression in a string

Do you mean Access 2003 (not Windows 2003)? The functions are definitely
there.

How are you trying to use the functions? (i.e.: where have you put Allen's
code?) What happens when you use them? Do you get an error message? If so,
what's the error?

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


"chinky" wrote in message
...

Thanks for the response.
I am using Windows 2003, but these functions are not available. Do I need
to
install something ?

"Allen Browne" wrote:

How about:

UBound(Split("asd.rty.de.com", "."))

Assumes Access 2000 or later.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"chinky" wrote in message
...
I want to count number of '.' (dots) in an expression e,g.
asd.rty.de.com
(answer = 3 dots at positions 4,8,11 respectively) . Instr functions
gives
only the first occurrence.
Any help is appreciated
Thanks
Anupam






  #7  
Old June 25th, 2006, 03:30 PM posted to microsoft.public.access.tablesdbdesign
external usenet poster
 
Posts: n/a
Default Count for multiple occurrence of an expression in a string

The version of Windows does not matter.

UBound() has been in Access for ever.
Split() has been part of Access since 2000.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"chinky" wrote in message
...

Thanks for the response.
I am using Windows 2003, but these functions are not available. Do I need
to
install something ?

"Allen Browne" wrote:

How about:

UBound(Split("asd.rty.de.com", "."))

Assumes Access 2000 or later.

"chinky" wrote in message
...
I want to count number of '.' (dots) in an expression e,g.
asd.rty.de.com
(answer = 3 dots at positions 4,8,11 respectively) . Instr functions
gives
only the first occurrence.



  #8  
Old June 25th, 2006, 06:32 PM posted to microsoft.public.access.tablesdbdesign
external usenet poster
 
Posts: n/a
Default Count for multiple occurrence of an expression in a string

Here's a function that does this type of counting:

' ***************************************
' ** Function CountCharacterOccurences **
' ***************************************

Public Function CountCharacterOccurences(ByVal strStringToSearch As Variant,
_
ByVal strCharacterToFind As String) As Long
' *** THIS FUNCTION COUNTS THE NUMBER OF TIMES A SINGLE CHARACTER IS FOUND
' *** IN A TEXT STRING. THE SEARCH IS CASE-INSENSITIVE.
' *** THE FUNCTION'S VALUE IS THE NUMBER OF TIMES THE SINGLE CHARACTER IS
FOUND.

Dim lngCountChars As Long, lngPosition As Long

On Error Resume Next

lngCountChars = 0
'truncate sChar in case it is longer than one character
strCharacterToFind = Left(strCharacterToFind, 1)

For lngPosition = 1 To Len(strStringToSearch)
'if character is found, increment the counter
If Mid(strStringToSearch, lngPosition, 1) = strCharacterToFind Then _
lngCountChars = lngCountChars + 1
Next lngPosition

CountCharacterOccurences = lngCountChars
Exit Function
End Function

--

Ken Snell
MS ACCESS MVP

"chinky" wrote in message
...
I want to count number of '.' (dots) in an expression e,g. asd.rty.de.com
(answer = 3 dots at positions 4,8,11 respectively) . Instr functions gives
only the first occurrence.
Any help is appreciated
Thanks
Anupam



  #9  
Old June 25th, 2006, 07:01 PM posted to microsoft.public.access.tablesdbdesign
external usenet poster
 
Posts: n/a
Default Count for multiple occurrence of an expression in a string

I think we need another possible solution.
=Len([YourExpression]) - Len(Replace([YourExpression],".",""))

Len("asd.rty.de.com") - Len(Replace("asd.rty.de.com",".","")) = 3

--
Duane Hookom
MS Access MVP

"chinky" wrote in message
...
I want to count number of '.' (dots) in an expression e,g. asd.rty.de.com
(answer = 3 dots at positions 4,8,11 respectively) . Instr functions gives
only the first occurrence.
Any help is appreciated
Thanks
Anupam



  #10  
Old June 26th, 2006, 04:32 PM posted to microsoft.public.access.tablesdbdesign
external usenet poster
 
Posts: n/a
Default Count for multiple occurrence of an expression in a string

This was very helpful to me. I really appreciate your help on this.
Thanks

"chinky" wrote:

I want to count number of '.' (dots) in an expression e,g. asd.rty.de.com
(answer = 3 dots at positions 4,8,11 respectively) . Instr functions gives
only the first occurrence.
Any help is appreciated
Thanks
Anupam

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Count Occurances of String in a Column? Bill General Discussion 4 February 23rd, 2006 12:30 AM
Print Search Listbox Results in Report Filter Preview ... HELP!!! [email protected] Setting Up & Running Reports 0 January 27th, 2006 07:34 PM
Requested string function Tom Ellison Running & Setting Up Queries 3 December 15th, 2005 06:58 PM
COUNT: Counting the number of times "X" comes up after the occurrence of "Y" DrSues02 General Discussion 5 August 3rd, 2004 06:35 AM
Tough One, trying to count occurences of string based on string in separate column RagDyer Worksheet Functions 2 February 28th, 2004 02:10 AM


All times are GMT +1. The time now is 02:15 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.