Desktop application C# strange behavior Replace and Substring function

  • Thread starter Thread starter Vano Abesadze
  • Start date Start date
V

Vano Abesadze

Guest
Hello,

So, there are lines DB.7DBD68 DB.7DVD72 DB.7DVD76 and since the following code

System.String temp ="DB.7DBD68";
temp=temp.Replace("DB.", "");
Int16 db = Int16.Parse(temp.Substring(0, temp.IndexOf("DB"))); //this code return 7 in db variable
temp = temp.Replace(temp.Substring(0, temp.IndexOf("DB")), "");
temp = temp.Replace("DBD", ""); //this code return 68 in temp variable




System.String temp ="DB.7DBD72";
temp=temp.Replace("DB.", "");
Int16 db = Int16.Parse(temp.Substring(0, temp.IndexOf("DB"))); //this code return 7 in db variable
temp = temp.Replace(temp.Substring(0, temp.IndexOf("DB")), "");
temp = temp.Replace("DBD", ""); //this code return 2 in temp variable

like this?

System.String temp ="DB.7DBD76";
temp=temp.Replace("DB.", "");
Int16 db = Int16.Parse(temp.Substring(0, temp.IndexOf("DB"))); //this code return 7 in db variable
temp = temp.Replace(temp.Substring(0, temp.IndexOf("DB")), "");
temp = temp.Replace("DBD", ""); //this code return 6 in temp variable

How can this be explained? the code is in a loop


Thanks

Continue reading...
 
Back
Top