Skip to content

Instantly share code, notes, and snippets.

@ClintChil
Last active September 24, 2018 17:59
Show Gist options
  • Save ClintChil/e1afdb0443e87a065d3926eaefc9f805 to your computer and use it in GitHub Desktop.
Save ClintChil/e1afdb0443e87a065d3926eaefc9f805 to your computer and use it in GitHub Desktop.
String Manipulaiton Practice
using System;
// To execute C#, please define "static void Main" on a class
// named Solution.
class Solution {
static string ReverseString(string inputString) {
if (inputString.Length <= 1)
return inputString;
else
return ReverseString(inputString.Substring(1, inputString.Length - 1)) + inputString[0];
}
static void Main(string[] args) {
var firstName = "Tom";
var lastName = "Smith";
var fullName = firstName + " " + lastName;
Console.WriteLine(ReverseString(firstName));
Console.WriteLine(ReverseString("Google"));
}
}
using System;
class Solution {
static string Sort(string s) {
char[] content = s.ToCharArray();
Array.Sort(content);
return new string(content);
}
static bool Permutation(string s, string t) {
if (s.Length != t.Length) {
return false;
} else {
return Sort(s).Equals(Sort(t));
}
}
static void Main(string[] args) {
Console.WriteLine(Permutation("taco", "cato"));
Console.WriteLine(Permutation("taco", "catt"));
}
}
using System;
class Solution {
static string Reverse(string str) {
string stringBuffer = String.Empty;
int length = str.Length;
for (int i = length - 1; i >= 0; i--) {
stringBuffer += str[i];
}
return stringBuffer;
}
static void Main(string[] args) {
Console.WriteLine(Reverse("taco"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment