83 lines
1.7 KiB
C#
83 lines
1.7 KiB
C#
namespace Iteration;
|
|
|
|
public class Iterations
|
|
{
|
|
public static int Reverseint(int n)
|
|
{
|
|
int result = 0;
|
|
if (n > 4)
|
|
{
|
|
for (int i = 0; i <= n; i++)
|
|
{
|
|
result = result * 10 + n % 10;
|
|
n /= 10;
|
|
}
|
|
|
|
if (n == 1)
|
|
{
|
|
return result * 10 + n;
|
|
}
|
|
}
|
|
else if (n < 4)
|
|
{
|
|
for (int i = 0; i >= n; i--)
|
|
{
|
|
result = result * 10 + n % 10;
|
|
n /= 10;
|
|
}
|
|
|
|
if (n == -1)
|
|
{
|
|
return result * 10 + n;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return n;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public static bool FindSub(string s, string sub)
|
|
{
|
|
if (sub == "")
|
|
{
|
|
throw new ArgumentException("sub cannot be empty");
|
|
}
|
|
string phrase = s;
|
|
string[] word = s.Split(' ');
|
|
foreach (var mot in word)
|
|
{
|
|
if (mot == sub)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static string FirstUpper(string s)
|
|
{
|
|
string phrase = s;
|
|
string[] word = s.Split(' ');
|
|
string result = String.Empty;
|
|
foreach (var element in word)
|
|
{
|
|
string first = element.Substring(0, 1);
|
|
result += first.ToUpper() + element.Substring(1) + " ";
|
|
}
|
|
|
|
return result.TrimEnd();
|
|
}
|
|
|
|
public static string ReplaceChar(string source, char toReplace, char replace)
|
|
{
|
|
string result = string.Empty;
|
|
result = source.Replace(toReplace, replace);
|
|
|
|
return result;
|
|
}
|
|
}
|