Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count # of slashes in a URL

Status
Not open for further replies.

kernal

Technical User
Feb 27, 2001
415
US
Is it possible to count the number of slashes in a URL? Example:


So I would want it to show 3 since this particular URL has 3 '/' slashes but some URLs could have 4, etc.

Help is appreciated
 
I found this select statement that is working.

Since there is no inbuilt MySQL function to count the occurrence of a character in string, we can do it by using these steps:

1. Counting the number of characters in the original string

2. Temporarily ‘deleting’ the character you want to count and count the string again

3. Subtract the first count from the second to get the number of occurrences

Example:

SELECT LENGTH('foobarfoobarfoobar') - LENGTH(REPLACE('foobarfoobarfoobar', 'b', '')) AS `occurrences`
--> Result: 3

In this example ‘b’ is the string you want to count the number of occurrences.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top