c# - Trying to restrict subsequent same character occurrences -
c# - Trying to restrict subsequent same character occurrences -
i trying implement similar functionality of alter directory (cd) in command prompt.
the restriction that, 1 . directory names must contain alphabets. 2 . root directory "/" 3 . parent directory ".." 4 . path separator "/"
the input new path name .
input might . 1. directory name alone. - valid 2. directory/directory/directory - valid 3. directory//directory - invalid 4. .. - valid 5. directory/.. - valid 6. directory/... - invalid
and other combinations that.
to avoid complexity tried split check
to check input must contain letters, used ^[a-za-z]+$ this. but don't know how restrict / , dot(.) characters subsequent occurences 1 , 2 respectivelythanks
you can utilize string.indexof
, check against it's homecoming value.
var is_only_one_slash = input.indexof("\\\\") == -1; var is_only_two_dots = input.indexof("..") > -1; if(is_only_one_slash && is_only_two_dots) { // valid }
c# regex
Comments
Post a Comment