Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace ChallengePhunWithStrings
- {
- public partial class Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- // 1. Reverse your name
- string name = "Jose Hernandez";
- // In my case, the result would be:
- // robaT boB
- for (int i = name.Length - 1; i >= 0; i--)
- {
- resultLabel.Text += name[i];
- }
- // 2. Reverse this sequence:
- string names = "Luke,Leia,Han,Chewbacca";
- // When you're finished it should look like this:
- // Chewbacca,Han,Leia,Luke
- //List<string> names = "Luke,Leia,Han,Chewbacca".Split(',').ToList<string>();
- //reverseLabel.Text = names.ToString();
- string[] reversedList = names.Split(',');
- string rev = "";
- for (int i = reversedList.Length - 1; i >= 0; i--)
- {
- rev += reversedList[i] + ",";
- }
- rev = rev.Remove(rev.Length - 1, 1);
- reverseLabel.Text = rev;
- string stWars = "Luke,Leia,Han,Chewbacca";
- // 3. Use the sequence to create ascii art:
- // *****luke*****
- // *****leia*****
- // *****han******
- // **Chewbacca***
- string[] starsCh = stWars.Split(',');
- string res = "";
- for (int i = 0; i < starsCh.Length; i++)
- {
- int padLeft = (14 - starsCh[i].Length) / 2;
- string tmp = starsCh[i].PadLeft(starsCh[i].Length + padLeft, '*');
- res += tmp.PadRight(14, '*') + "<br />";
- //res += "<br />";
- asciiLabel.Text = res;
- }
- // 4. Solve this puzzle:
- string puzzle = "NOW IS ZHEremove-me ZIME FOR ALL GOOD MEN ZO COME ZO ZHE AID OF ZHEIR COUNZRY.";
- // Once you fix it with string helper methods, it should read:
- // Now is the time for all good men to come to the aid of their country.
- string rem = "remove-me";
- int index = puzzle.IndexOf(rem);
- puzzle = puzzle.Remove(index, rem.Length);
- puzzle = puzzle.ToLower();
- puzzle = puzzle.Replace('z', 't');
- puzzle = puzzle.Remove(0, 1);
- puzzle = puzzle.Insert(0, "N");
- starLabel.Text = puzzle;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement