469,590 Members | 2,464 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,590 developers. It's quick & easy.

poor string function

why c# function for string manupolation is not as strong as other languages
,for extracting a substring from a middle of another string ,I have a lot of
problems.

Any suggestion or I am in the wrong spot.
Thanks
Nov 16 '05 #1
11 1387
What problem are you having? Does the SubString method not work?

-Rob Teixeira

"ALI-R" <al*@microsoft.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
why c# function for string manupolation is not as strong as other languages ,for extracting a substring from a middle of another string ,I have a lot of problems.

Any suggestion or I am in the wrong spot.
Thanks

Nov 16 '05 #2
What's wrong with "Substring" ?

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 16 '05 #3
hi.....

seems like a heated debate on this topic, count me in.......

if u cud say the issue, probably we can give you some solutions or may be
suggestions.....

Kannan.V

"David Anton" wrote:
What's wrong with "Substring" ?

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*

Nov 16 '05 #4
ALI-R <al*@microsoft.com> wrote:
why c# function for string manupolation is not as strong as other languages
C# itself has almost *no* string manipulation at all. The .NET
framework has plenty though. That's the way it should be, IMO.
for extracting a substring from a middle of another string ,I have a lot of
problems.


That sounds like your problem rather than the framework's or C#'s, but
perhaps if you could tell us more about the problems you're having, we
could help you. Here's an example of getting a substring:

string x = "abcdefg";
string y = x.Substring (2, 3);

y is now "cde" - 3 characters, starting from position 2 ('c') of x.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
Why dont u use regular expressions....
Nov 16 '05 #6
Because they're slower, and unnecessary if you already know the position in
the string you want to extract from. But if you don't, then you should use
them.

"darin" <da***@discussions.microsoft.com> wrote in message
news:2E**********************************@microsof t.com...
Why dont u use regular expressions....

Nov 16 '05 #7
<"Bonj" <benjtaylor at hotpop d0t com>> wrote:
Because they're slower, and unnecessary if you already know the position in
the string you want to extract from. But if you don't, then you should use
them.


Again, not necessarily. If you want to get the rest of the string from
the first colon onwards, using a regular expression seems over the top
to me when IndexOf and Substring will do the trick perfectly easily.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #8
Seems to be stimulating your sense of proud self-confidence on C#
capability in string manipulation,ok here we go,GET FIGHTED:
I have a string like string pathFolder=
"http://serverdev.hag.net/Operation/Document Library"

I want to split it into these three segments:
1) "http://serverdev.hag.net"
2)"Operation"
3)Document Library

I did it in this way but I don't like the way that I didit,is there a better
of doing that?

docLibName= pathFolder.Substring(pathFolder.LastIndexOf("/") + 1);

subarea= tmpStr.Substring(tmpStr.LastIndexOf("/") + 1);

portalName=
tmpStr.Remove(tmpStr.LastIndexOf("/"),(tmpStr.Substring(tmpStr.LastIndexOf("
/"))).Length);

thanks for your help
Nov 16 '05 #9
Sorry here is the complete code I used"

docLibName= pathFolder.Substring(pathFolder.LastIndexOf("/") + 1);
string tmpStr= pathFolder.Remove(pathFolder.Length -
docLibName.Length -1,docLibName.Length + 1);

subarea= tmpStr.Substring(tmpStr.LastIndexOf("/") + 1);

portalName=
tmpStr.Remove(tmpStr.LastIndexOf("/"),(tmpStr.Substring(tmpStr.LastIndexOf("
/"))).Length);

"ALI-R" <al*@microsoft.com> wrote in message
news:OW**************@TK2MSFTNGP09.phx.gbl...
Seems to be stimulating your sense of proud self-confidence on C#
capability in string manipulation,ok here we go,GET FIGHTED:
I have a string like string pathFolder=
"http://serverdev.hag.net/Operation/Document Library"

I want to split it into these three segments:
1) "http://serverdev.hag.net"
2)"Operation"
3)Document Library

I did it in this way but I don't like the way that I didit,is there a better of doing that?

docLibName= pathFolder.Substring(pathFolder.LastIndexOf("/") + 1);

subarea= tmpStr.Substring(tmpStr.LastIndexOf("/") + 1);

portalName=
tmpStr.Remove(tmpStr.LastIndexOf("/"),(tmpStr.Substring(tmpStr.LastIndexOf(" /"))).Length);

thanks for your help

Nov 16 '05 #10
ALI-R <al*@microsoft.com> wrote:
Sorry here is the complete code I used"

docLibName= pathFolder.Substring(pathFolder.LastIndexOf("/") + 1);
string tmpStr= pathFolder.Remove(pathFolder.Length -
docLibName.Length -1,docLibName.Length + 1);


I think I'd just use

int lastSlash = pathFolder.LastIndexOf('/');

// Do some error checking here, just in case there aren't any slashes
// or it's reached the http:// part

string docLibName = pathFolder.Substring (lastSlash+1);
string previousSlash = pathFolder.LastIndexOf('/', lastSlash-1);

// Again, do error checking

string subArea = pathFolder.Substring (previousSlash+1,
lastSlash-previousSlash-1);
string portalName = pathFolder.Substring (0, previousSlash);

Alternatively, take the substring after http:// and then use
String.Split.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #11
ALI-R,
Have you tried using System.Uri and/or System.IO.Path to parse the file name
into the respective parts?

Something like:

string pathFolder = "http://serverdev.hag.net/Operation/Document
Library";
Uri uri = new Uri(pathFolder);
// 1) "http://serverdev.hag.net"
string portalName = uri.Host;

// 2)"Operation"
string subarea = Path.GetDirectoryName(uri.LocalPath);

// 3)Document Library
string docLibName= Path.GetFileName(uri.LocalPath);

Hope this helps
Jay
"ALI-R" <al*@microsoft.com> wrote in message
news:OW**************@TK2MSFTNGP09.phx.gbl...
Seems to be stimulating your sense of proud self-confidence on C#
capability in string manipulation,ok here we go,GET FIGHTED:
I have a string like string pathFolder=
"http://serverdev.hag.net/Operation/Document Library"

I want to split it into these three segments:
1) "http://serverdev.hag.net"
2)"Operation"
3)Document Library

I did it in this way but I don't like the way that I didit,is there a
better
of doing that?

docLibName= pathFolder.Substring(pathFolder.LastIndexOf("/") + 1);

subarea= tmpStr.Substring(tmpStr.LastIndexOf("/") + 1);

portalName=
tmpStr.Remove(tmpStr.LastIndexOf("/"),(tmpStr.Substring(tmpStr.LastIndexOf("
/"))).Length);

thanks for your help

Nov 16 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Ion | last post: by
4 posts views Thread by JM | last post: by
3 posts views Thread by John Smith | last post: by
20 posts views Thread by John Mark Howell | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.