I tried it my way, want to know where am i going wrong and to know how to replace int variable value to one of the index of char array?
string time = "07:05:45PM";
string result = string.Empty;
char[] time_Char = time.ToCharArray();
int first_Char = (int)Char.GetNumericValue(time_Char[0]) + 1;
int second_Char = (int)Char.GetNumericValue(time_Char[1]) + 2;
time_Char[0] = Convert.ToChar(first_Char);
time_Char[1] = Convert.ToChar(second_Char);
for (int i = 0; i < time_Char.Length; i++)
{
result += time_Char[i];
}
Console.WriteLine(result);
Output - :05:45PM
Expected Output - 19:05:45PM
Convert.ToChar(first_Char)turns a integer to a character with the corresponding character code, not one that has the equivalent numeral face-value. This the same reason as to whyChar.GetNumericValuemust be used instead ofConvert.ToInt32: so what is the 'opposite' ofChar.GetNumericValue?