using System;
using static
System.Console;
namespace CSarpExamples
{
class UpperLowerchar
{
public static string ToUpper(string str)
{
string result = str;
if (!string.IsNullOrEmpty(str))
{
var word = str.Split(' ');
for (int i = 0; i
< word.Length; i++)
{
string s = word[i];
if (s.Length > 0)
{
word[i] =
s[0].ToString().ToUpper() + s.Substring(1);
}
}
result = string.Join("
", word);
}
return result;
}
public static string ToLower(string str)
{
string result = str;
if (!string.IsNullOrEmpty(str))
{
var word = str.Split(' ');
for (int i = 0; i
< word.Length; i++)
{
string s = word[i];
if (s.Length > 0)
{
word[i] =
s[0].ToString().ToLower() + s.Substring(1);
}
}
result = string.Join("
", word);
}
return result;
}
static void Main()
{
string FinalResult;
NextLine:
Console.WriteLine("Enter the string");
string result = ReadLine();
FinalResult = result;
if (FinalResult == result.ToUpper())
{
var testResult = ToLower(FinalResult);
WriteLine(testResult);
WriteLine();
}
else if (FinalResult
== result.ToLower())
{
var testResult = ToUpper(FinalResult);
WriteLine(testResult);
goto NextLine;
}
ReadLine();
}
}
}
Output:
No comments:
Post a Comment