I assume that "1,2,4,6" is just an example?
If your string is always going to be comma separated, then consider splitting the string, and rebuilding it:
string myString = "1,2,4,6";
string[] parts = myString.Split(',');
StringBuilder sb = new StringBuilder();
sb.Append(parts[0]);
sb.Append(",");
sb.Append(parts[1]);
sb.Append(",3,");
sb.Append(parts[2]);
sb.Append(",5,");
sb.Append(parts[3]);
myString = sb.toString():
"Dear Sir,
I Get String From Runtime I Dont Know How It Will Came Either Like (1,2,5,7) Or Else (3,4,6) So On.. Here My Problem Is I Need To Add Missing Values"
Then I would do much the same as above, but use the first and last values to generate the intermediate ones:
string myString = "1,2,4,6";
string[] parts = myString.Split(',');
int first = int.Parse(parts[0]);
int last = int.Parse(parts[parts.Length - 1]);
StringBuilder sb = new StringBuilder();
string separator = "";
for (int i = first; i <= last; i++)
{
sb.Append(separator);
sb.Append(i.ToString());
separator = ",";
}
myString = sb.ToString();
Console.WriteLine(myString);
This assumes that the incoming string is effectively sorted! If not, then you have to do something about that first!