How to count # of character occurrences in a string .NET vERSION
A quick way to find the number of occurrences of a character in a string could go something as shown below.
Dim x As String = “aa:bb:cc:dd”
Dim num As Integer = Len(x) – Len(Replace(x, “:”, “”))
How to count # of character occurrences in a string
A quick and dirty way would be to use an expression like
length(x) – length(replace(x, “:”, “”))
Here’s some code that I actually ran:
set @x = “aa:bb:cc:dd”;
set @colons = length(@x) – length(replace(@x, “:”, “”));
select @x , @colons;
Example 2:
try to count how many times p appears in word ‘Mississippi’
select len(‘Mississippi’) – len(replace(‘Mississippi’, ‘p’, ”))
-
Recent
- How To Implement Custom Rounding Procedures
- How to count # of character occurrences in a string .NET vERSION
- How to count # of character occurrences in a string
- Easier way to manage your ASP.NET Cache
- Working with Dates and Time in ASP.NET
- How to invoke events across User Controls in ASP.NET
- HttpCacheVaryByParams Class
-
Links
-
Archives
- July 2009 (1)
- February 2009 (2)
- June 2008 (3)
- December 2007 (1)
-
Categories
-
RSS
Entries RSS
Comments RSS