How can empty string be added to a a string?
if your string has something in it, then you can never see an empty string as part of the string.
Think you are miss understanding something.
In the code above if you stop the execution
on the line,
string str="Hai";
, then it is possible that
str = empty.string
until after this line as "Hai" will not be assigned until you pass through this line.
if you add a breakpoint immediately after this line and look at the variables
str
will equal
"Hai"
.
See the following code; it will test a string for String.Empty, and also for the position of the first known character 'a'; you will see that position positions come back the same. It is not a case of a String.empty being added anywhere, it is just how the system deals with 'nothing';
string str = "aaa";
if (str.Contains(String.Empty))
MessageBox.Show("String aaa contains an empty string");
int pos = str.IndexOf(String.Empty);
int pos2 = str.IndexOf("a");
MessageBox.Show("String.Empty at Position: " + pos.ToString());
MessageBox.Show("First 'a' is at Position: " + pos.ToString());
MessageBox.Show("The 2 position index match: " + (pos == pos2));