LastIndexOf("") in C#
-
My Url is "http://sampleTesting:9587/MyFolder" My expecting result is MyFolder I have used the following code , its work fine. int iStartIndex = srcUrl.LastIndexOf("/"); string sitePath = srcUrl.Remove(iStartIndex); Here I have used only one parameter ie., LastIndexOf("/"). But I should use two parameters for example name="My name is jayaraj"; int foundS1 = name.IndexOf(" "); int foundS2 = name.IndexOf(" ", foundS1 + 1); name = name.Remove(foundS1 + 1, foundS2 - foundS1); in the same way i want . pls give the code
-
My Url is "http://sampleTesting:9587/MyFolder" My expecting result is MyFolder I have used the following code , its work fine. int iStartIndex = srcUrl.LastIndexOf("/"); string sitePath = srcUrl.Remove(iStartIndex); Here I have used only one parameter ie., LastIndexOf("/"). But I should use two parameters for example name="My name is jayaraj"; int foundS1 = name.IndexOf(" "); int foundS2 = name.IndexOf(" ", foundS1 + 1); name = name.Remove(foundS1 + 1, foundS2 - foundS1); in the same way i want . pls give the code
-
My Url is "http://sampleTesting:9587/MyFolder" My expecting result is MyFolder I have used the following code , its work fine. int iStartIndex = srcUrl.LastIndexOf("/"); string sitePath = srcUrl.Remove(iStartIndex); Here I have used only one parameter ie., LastIndexOf("/"). But I should use two parameters for example name="My name is jayaraj"; int foundS1 = name.IndexOf(" "); int foundS2 = name.IndexOf(" ", foundS1 + 1); name = name.Remove(foundS1 + 1, foundS2 - foundS1); in the same way i want . pls give the code
jayarajmrj wrote:
My Url is "http://sampleTesting:9587/MyFolder" My expecting result is MyFolder
I think what you need is
string sitePath = srcUrl.SubString(iStartIndex + 1);
Cheers, Vıkram.
After all is said and done, much is said and little is done.
-
My Url is "http://sampleTesting:9587/MyFolder" My expecting result is MyFolder I have used the following code , its work fine. int iStartIndex = srcUrl.LastIndexOf("/"); string sitePath = srcUrl.Remove(iStartIndex); Here I have used only one parameter ie., LastIndexOf("/"). But I should use two parameters for example name="My name is jayaraj"; int foundS1 = name.IndexOf(" "); int foundS2 = name.IndexOf(" ", foundS1 + 1); name = name.Remove(foundS1 + 1, foundS2 - foundS1); in the same way i want . pls give the code
Hi, if you need to find the last slash, a single invocation of LastIndexOf would do it, and it would need only one parameter. If you give LastIndexOf a start parameter as well, be careful it will search from that position down to index zero. And I guess you could tackle the problem with the URI class too. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google