Advertisement
FrayxRulez

Untitled

Oct 23rd, 2016
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1.         private static bool SearchByUsernames(string text, int position, out string searchText)
  2.         {
  3.             if (text.Length == 0)
  4.             {
  5.                 searchText = string.Empty;
  6.                 return false;
  7.             }
  8.  
  9.             var found = false;
  10.             var index = -1;
  11.             var length = 0;
  12.  
  13.             for (int i = position - 1; i >= 0; i--)
  14.             {
  15.                 if (text[i] == '@')
  16.                 {
  17.                     found = true;
  18.                     index = i;
  19.                     break;
  20.                 }
  21.             }
  22.  
  23.             if (found)
  24.             {
  25.                 for (int i = index + 1; i < position; i++)
  26.                 {
  27.                     if (IsValidUsernameSymbol(text[i]))
  28.                     {
  29.                         length++;
  30.                     }
  31.                     else
  32.                     {
  33.                         found = false;
  34.                         break;
  35.                     }
  36.                 }
  37.             }
  38.  
  39.             if (found)
  40.             {
  41.                 searchText = text.Substring(index + 1, length);
  42.             }
  43.             else
  44.             {
  45.                 searchText = string.Empty;
  46.             }
  47.  
  48.             return found;
  49.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement