Advertisement
joseh254

working now

Mar 19th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7.  
  8. namespace ChallengePhunWithStrings
  9. {
  10.     public partial class Default : System.Web.UI.Page
  11.     {
  12.         protected void Page_Load(object sender, EventArgs e)
  13.         {
  14.             // 1.  Reverse your name
  15.             string name = "Jose Hernandez";
  16.             // In my case, the result would be:
  17.             // robaT boB
  18.             for (int i = name.Length - 1; i >= 0; i--)
  19.             {
  20.                 resultLabel.Text += name[i];
  21.             }
  22.  
  23.  
  24.            
  25.             // 2.  Reverse this sequence:
  26.             string names = "Luke,Leia,Han,Chewbacca";
  27.             // When you're finished it should look like this:
  28.             // Chewbacca,Han,Leia,Luke
  29.             //List<string> names = "Luke,Leia,Han,Chewbacca".Split(',').ToList<string>();
  30.             //reverseLabel.Text = names.ToString();
  31.            
  32.             string[] reversedList = names.Split(',');
  33.             string rev = "";
  34.             for (int i = reversedList.Length - 1; i >= 0; i--)
  35.             {
  36.                 rev += reversedList[i] + ",";
  37.             }
  38.             rev = rev.Remove(rev.Length - 1, 1);
  39.             reverseLabel.Text = rev;
  40.            
  41.  
  42.  
  43.             string stWars = "Luke,Leia,Han,Chewbacca";
  44.             // 3. Use the sequence to create ascii art:
  45.             // *****luke*****
  46.             // *****leia*****
  47.             // *****han******
  48.             // **Chewbacca***
  49.            
  50.             string[] starsCh = stWars.Split(',');
  51.             string res = "";
  52.             for (int i = 0; i < starsCh.Length; i++)
  53.             {
  54.                 int padLeft = (14 - starsCh[i].Length) / 2;
  55.                 string tmp = starsCh[i].PadLeft(starsCh[i].Length + padLeft, '*');
  56.                 res += tmp.PadRight(14, '*') + "<br />";
  57.                 //res += "<br />";
  58.                 asciiLabel.Text = res;
  59.             }
  60.            
  61.  
  62.  
  63.            
  64.  
  65.  
  66.             // 4. Solve this puzzle:
  67.            
  68.             string puzzle = "NOW IS ZHEremove-me ZIME FOR ALL GOOD MEN ZO COME ZO ZHE AID OF ZHEIR COUNZRY.";
  69.  
  70.             // Once you fix it with string helper methods, it should read:
  71.             // Now is the time for all good men to come to the aid of their country.
  72.             string rem = "remove-me";
  73.             int index = puzzle.IndexOf(rem);
  74.             puzzle = puzzle.Remove(index, rem.Length);
  75.             puzzle = puzzle.ToLower();
  76.             puzzle = puzzle.Replace('z', 't');
  77.             puzzle = puzzle.Remove(0, 1);
  78.             puzzle = puzzle.Insert(0, "N");
  79.  
  80.             starLabel.Text = puzzle;
  81.            
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement