Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static bool SearchByUsernames(string text, int position, out string searchText)
- {
- if (text.Length == 0)
- {
- searchText = string.Empty;
- return false;
- }
- var found = false;
- var index = -1;
- var length = 0;
- for (int i = position - 1; i >= 0; i--)
- {
- if (text[i] == '@')
- {
- found = true;
- index = i;
- break;
- }
- }
- if (found)
- {
- for (int i = index + 1; i < position; i++)
- {
- if (IsValidUsernameSymbol(text[i]))
- {
- length++;
- }
- else
- {
- found = false;
- break;
- }
- }
- }
- if (found)
- {
- searchText = text.Substring(index + 1, length);
- }
- else
- {
- searchText = string.Empty;
- }
- return found;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement