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. |
|
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
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 |