Advertisement
stoianpp

PHP variables

Jan 21st, 2014
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. class PHP
  8. {
  9.     static void Main()
  10.     {
  11.         string line = string.Empty;
  12.         string currLine = Console.ReadLine();
  13.         StringBuilder fullLine = new StringBuilder();
  14.        
  15.         while(currLine != "?>")
  16.         {
  17.             currLine = Regex.Replace(Console.ReadLine(), @"(//|#).*", "");
  18.             fullLine.AppendLine(currLine);
  19.         }
  20.        
  21.         line = fullLine.ToString();
  22.         line = Regex.Replace(line, @"(/\*).*?(\*/)", "");
  23.         HashSet<string> results = new HashSet<string>();
  24.        
  25.     Match variable = Regex.Match(line, @"([^\\])\$([a-zA-Z_](\w*)?)");
  26.     while (variable.Success)
  27.         {
  28.         results.Add(variable.Groups[2].Value);
  29.             variable = variable.NextMatch();    
  30.         }
  31.  
  32.         string[] print = new string[results.Count];
  33.         for (int i = 0; i < results.Count; i++) print[i] = results.ElementAt(i);
  34.         Printing (print);
  35.     }
  36.  
  37.     static void Printing(string[] print)
  38.     {
  39.         Array.Sort<string>(print);
  40.         Console.WriteLine(print.Length);
  41.         List<string> notUpper = new List<string>();
  42.        
  43.     for(int i = 0; i < print.Length; i++)
  44.         {
  45.             if(!char.IsUpper(print[i][0]))
  46.             {
  47.                 notUpper.Add(print[i]);
  48.                 continue;
  49.             }
  50.             Console.WriteLine(print[i]);
  51.         }
  52.        
  53.     for (int i = 0; i < notUpper.Count; i++)
  54.         {
  55.             Console.WriteLine(notUpper[i]);
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement