-
January 19th, 2014, 06:00 PM
#1
Need some help explaining the code
Could someone explain whats going on in this little segment of code? what each line does if possible please
Code:
static string[] groups = { "AEIOUHWY", "BFPV", "CGJKQSXZ", "DT", "L", "MN", "R" };
static string getCode(string str)
{
string tempstr = "";
int i;
for (i = 0; i < 7; i++)
{
if (groups[i].Contains(str))
{
tempstr = i.ToString();
break;
}
}
return tempstr;
}
static string encodeString(string str)
{
string tempstr = "";
int i;
for (i = 0; i < str.Length; i++)
{
tempstr = tempstr + getCode(str.Substring(i, 1));
}
return tempstr;
}
static string removeZeroes(string str)
{
string tempstr = "";
int i;
for (i = 0; i < str.Length; i++)
{
if (str.Substring(i, 1) != "0")
{
tempstr = tempstr + str.Substring(i, 1);
}
}
return tempstr;
}
static string RemoveAdjacent(string str)
{
string tempstr = "";
int i;
string stringToCheckAgainst = "#";
for (i = 0; i < str.Length; i++)
{
if (str.Substring(i, 1) != stringToCheckAgainst)
{
tempstr = tempstr + str.Substring(i, 1);
stringToCheckAgainst = str.Substring(i, 1);
}
}
return tempstr;
}
}
}
-
January 19th, 2014, 07:31 PM
#2
Re: Need some help explaining the code
Looks like you can encode, but never decode. It tries to convert each letter into a code, which can have 0's (which it removes) and duplicate characters next to each other 1, 11, 111 (only leave 1 in each instance) to create a string of 1-9, with no repeats
-
January 19th, 2014, 09:21 PM
#3
Re: Need some help explaining the code
To really understand, you'll need to look at the code that calls these methods.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|