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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

counting characters

Status
Not open for further replies.

aybooth

MIS
Joined
Feb 6, 2004
Messages
9
Location
US
I need to know how to count the number of specified charecters within a string of text. i.e. how many B's appear within "BBB12BBB" = 6.

Thanks
 
You'd need to use the substring function within a loop and check each character, no time to check the syntax, but something like this
my_string = "BBB12BBB";

do for i = 1 to length(my_string);
if substr(my_string,i,1) = "B" then count+1;
end;

Another alternative:-
first_count = length(my_string)
new_string = compress(my_string,'B');
second_count = length(new_string);

Number_of_bs = first_count - second_count;

Enjoy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top