Advertisement
kyrathasoft

index of non-alphanumeric character in string

May 21st, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1.         public static int IndexOfNonAlphanumericCharacter(string p, bool excludeSpaces){
  2.             int index = -1;
  3.                    
  4.             if(p.Length < 1){
  5.                 //done
  6.             }else{
  7.                 char[] chars = p.ToCharArray();
  8.                 for(int i=0; i < chars.Length; i++){
  9.                     if(IsNonAlphaNumChar(chars[i])){
  10.                         if(chars[i] == ' '){
  11.                             if(excludeSpaces){
  12.                                 //ignore
  13.                             }else{
  14.                                 index = i;
  15.                                 break;                             
  16.                             }
  17.                         }else{
  18.                             index = i;
  19.                         }
  20.  
  21.                     }
  22.                 }
  23.             }
  24.            
  25.             return index;
  26.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement