Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Just so that YOU all know, I DID search through all of the posted questions and others online. My issue is that I have created a string function in VB 2012 that (has some arguments). It searches specific locations in a 25 x 25 character array and returns a string of 3 to 10 characters in length. This string will be made up of capital letters (of words) and "*".

I'd like to use:

VB
String.Replace("*", "").Count


to determine the number of these characters in the returned string. How do I do this?

What I have tried:

I've tried:

VB
MyFunction([some arguments]).Replace("*", "").Count


but it dont work. I don't even think my function is returning the string properly.
Posted
Updated 2-Aug-18 19:32pm

Quote:
but it dont work. I don't even think my function is returning the string properly.

Displaying the result you get may help you to know if the function works properly or not.
VB
MyFunction([some arguments]).Replace("*", "").Count

Replace is a RegEx function, and in RegEx , '*' is a special char. you probaly need to change it ti '\*'

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
This site also show the Regex in a nice graph but can't test what match the RegEx:
Regexper[^]
 
Share this answer
 
Comments
[no name] 3-Aug-18 12:37pm    
Thank you but I figured it out. The function call was being made from within an "IF" statement and the function had no value. I assigned the functions value to a temp variable and then tried the Replace - it worked!
Patrice T 3-Aug-18 13:34pm    
Nice to hear it.
It is always better to post some code that we can run.
Have a look at this: Counting Lines in a String[^] - it's about lines, but that just means that it specifically looks for '\n' - it's simple to change that - and the code is C# rather than VB, but it's mostly pretty trivial code. If you can't understand it, then online converters like this may help: Code Converter C# to VB and VB to C# – Telerik[^]
It presents quite a few different ways to do it, together with their relative speeds.
 
Share this answer
 
Comments
[no name] 3-Aug-18 12:37pm    
Thank you but I figured it out. The function call was being made from within an "IF" statement and the function had no value. I assigned the functions value to a temp variable and then tried the Replace - it worked!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900