how to find substring position length

Posted by Oswaldlily under ASP.NET on 11/23/2011 | Points: 10 | Views : 7055 | Status : [Member] | Replies : 5
string s="asdsdsdsd sdsdsadsd";
s.substring(12,?);
"?" this value is not constant ...so how to find its length




Responses

Posted by: RohiK on: 11/23/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

its s.length

s.substring(12,s.length);


Happy Programming!!
Rohi

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Niladri.biswas on: 11/23/2011 [Member] Platinum | Points: 25

Up
0
Down
string s="asdsdsdsd sdsdsadsd";

var res = s.Substring(12,s.Length - 12);


Best Regards,
Niladri Biswas

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Niladri.biswas on: 11/23/2011 [Member] Platinum | Points: 25

Up
0
Down
Hi RohiK,
Throwing error

Index and length must refer to a location within the string.
Parameter name: length


Best Regards,
Niladri Biswas

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: RohiK on: 11/25/2011 [Member] Starter | Points: 25

Up
0
Down
ohh ya you can use

s.substring(12,s.length-1);

Happy Programming!!
Rohi

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajeev.Shukla on: 11/25/2011 [Member] Starter | Points: 25

Up
0
Down
string s="asdsdsdsd sdsdsadsd";

Substring():
It ahs Two oveloaded method.
1. Substring(int StartIndex):
This gives the output up to last index starts from the given start Index.

e.g, s.SubString(12): The output will be "sdsadsd" i,e it starts from 12th index to last index.

2. Substring(int StartIndex, int Length):
This gives the output as per Start Index to the length given.

e.g, s.SubString(12,3): The output will be "sds" i,e it starts from 12th index to 3 length only.




Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response