c# - Regex Counting Characters in a text field -


i trying count characters in text field. found how count characters.

string st = textbox1.text; this.textbox2.text = regex.matches(st, ".|").count.tostring(); 

but need create 2 more separate counts, caps, numbers, - or # (not including) @

eg. la-fg4-detf-djjjthd-s@t-jhf-f1-f2 count 21

and other 1 need count @ (including) , caps, numbers, - or # end of text field.

eg. la-fg4-detf-djjjthd-s@t-jhf-f1-f2 count 12

any appreciated.

 string input = "la-fg4-detf-djjjthd-s@t-jhf-f1-f2"; int atindex = input.indexof('@'); int count1 = regex.matches(input.substring(0, atindex), "[0-9a-z#-]").count; int count2 = regex.matches(input.substring(atindex, input.length - atindex), "[0-9a-z#@-]").count; 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -