I am unable to understand why this use of Substring does not work

  • Thread starter Thread starter intrader
  • Start date Start date
I

intrader

Looking at the watch window, I have
----------------watch window-----------------------
ix 6 int
tStr "hyphen, and )(*" string

tStr.Substring(0,ix) error:'tStr.Substring' does not exist
---------------------------------------------------


I have no errors in the compile, and the following works:

string s="1234567890";
s=s.Substring(0,6)
----------------watch window-----------------------
s.Substring(0,6) "123456"
 
intrader said:
Looking at the watch window, I have
----------------watch window-----------------------
ix 6 int
tStr "hyphen, and )(*" string

tStr.Substring(0,ix) error:'tStr.Substring' does not exist
---------------------------------------------------


I have no errors in the compile, and the following works:

string s="1234567890";
s=s.Substring(0,6)
----------------watch window-----------------------
s.Substring(0,6) "123456"
I think I figured out. It appears that the IDE is paying attention to
the generated code.

The full expression I have is

tStr=tStr.Subsring(0,ix) + tStr(ix+1, tStr.Length-1);

which causes the index to be out of the string.

The expression should be

tStr=tStr.Subsring(0,ix) + tStr(ix+1, tStr.Length-ix-1);

Thanks for anyone looking at this.
 
intrader said:
I think I figured out. It appears that the IDE is paying attention to
the generated code.

The full expression I have is

tStr=tStr.Subsring(0,ix) + tStr(ix+1, tStr.Length-1);

which causes the index to be out of the string.

The expression should be

tStr=tStr.Subsring(0,ix) + tStr(ix+1, tStr.Length-ix-1);

Thanks for anyone looking at this.

That's why I coldn't see anything wrong with the code you posted... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top