471,310 Members | 1,018 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 software developers and data experts.

extracting substring


string comm="CONTSCAN E:\\projects backup\\ankitclam
backup\\Clamtest\\testing\\hello.txt\r\n"
int x=comm.Length;
x=x-7;
string path;
path=comm.Substring(9,x);
MessageBox.Show(path);

it works fine and give path as
E:\projects backup\ankitclam backup\Clamtest\testing\hello.txt

but when i give path
string comm="CONTSCAN E:\\projects backup\\ankitclam
backup\\Clamtest\\testing\r\n"
int x=comm.Length;
x=x-7;
string path;
path=comm.Substring(9,x); //crashes here
MessageBox.Show(path);

crashes on line : path=comm.Substring(9,x);

throwing exception
System.Argument.OutOfRangeException:Index and length must refer to location
within the string.
Parameter name:length
at System.String.Substring(Int32 startIndex,Int32 length)
Dec 13 '05 #1
0 1072

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by cpp_weenie | last post: by
3 posts views Thread by Abby Lee | last post: by
3 posts views Thread by War Eagle | last post: by
1 post views Thread by annaannie | last post: by
1 post views Thread by Phat G5 (G3) | last post: by
11 posts views Thread by Ebenezer | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.