Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class PHPVariables
  8. {
  9.     static void Main()
  10.     {
  11.         StringBuilder text = new StringBuilder();
  12.         StringBuilder result = new StringBuilder();
  13.         HashSet<string> existing = new HashSet<string>();
  14.         string line = Console.ReadLine().Trim();
  15.  
  16.         while (line != "?>")
  17.         {
  18.             text.AppendLine(line);
  19.             line = Console.ReadLine().Trim();
  20.         }
  21.  
  22.         bool oneLineComment = false;
  23.         bool moreLineComment = false;
  24.         int counter = 0;
  25.         for (int i = 0; i < text.Length; i++)
  26.         {
  27.             if (text[i].ToString() == "/" || text[i].ToString() == "#")
  28.             {
  29.                 oneLineComment = true;
  30.             }
  31.             else if (text[i] == '\n')
  32.             {
  33.                 oneLineComment = false;
  34.             }
  35.             else if (text[i].ToString() == "/*")
  36.             {
  37.                 moreLineComment = true;
  38.             }
  39.             else if (text[i].ToString() == "*/")
  40.             {
  41.                 moreLineComment = false;
  42.             }
  43.  
  44.             if (!oneLineComment && !moreLineComment)
  45.             {
  46.                 if (text[i] == '\\')
  47.                 {
  48.                     i += 2;
  49.                 }
  50.                 if (text[i] == '$')
  51.                 {
  52.                     if (char.IsNumber(text[i + 1]) || char.IsLetter(text[i + 1]) || text[i + 1] == '_')
  53.                     {
  54.                         counter++;
  55.                         i++;
  56.                         while (char.IsNumber(text[i]) || char.IsLetter(text[i]) || text[i] == '_')
  57.                         {
  58.                             result.Append(text[i]);
  59.                             i++;
  60.                         }
  61.                         existing.Add(result.ToString());
  62.                         result.Clear();
  63.                         i--;
  64.                     }
  65.                 }
  66.             }
  67.         }
  68.         Console.WriteLine(counter);
  69.         Console.WriteLine(string.Join("\n",existing));
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement