473,508 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1521
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2859
by: Ion | last post by:
Hi all, I have a query that takes almost 1 hour to complete. This is acceptable in certain situations, but unacceptable when no rows should qualify. Something like: Select list >From...
4
2221
by: JM | last post by:
Hi I have a Windows Form that I have 3 textboxes and some buttons. Below is the code that I have implemented it reads a pile of files from a folder and then reads each of the files. If the...
10
399
by: Segfahlt | last post by:
I have a fairly simple C# program that just needs to open up a fixed width file, convert each record to tab delimited and append a field to the end of it. The input files are between 300M and...
3
1144
by: John Smith | last post by:
Here's the scenario... First let me say that the following events were catastrophic to my development workstation because my C:\WINNT directory had the EVERYONE user group assigned with full...
11
3107
by: youngster94 | last post by:
Hey all, I've written a VB.Net app that creates picture badges complete with barcodes. The problem is that the barcode quality is not good enough to be read by scanners. I'm using the...
20
2083
by: John Mark Howell | last post by:
I had a customer call about some C# code they had put together that was handling some large arrays. The performance was rather poor. The C# code runs in about 22 seconds and the equivalent...
11
2333
by: John Fly | last post by:
I'm working on a large project(from scratch). The program is essentially a data file processor, the overall view is this: A data file is read in, validated and stored in a memory structure...
1
3877
by: Billy | last post by:
Hi All, I'm attempting to use the MapNetworkDrive <snippedbelow from entire code below with very poor performance results. Basically, I have very small 73kb text files that are rewritten daily...
6
6378
by: Bob | last post by:
Hi, I have a fairly large but not massive project. Visual Studio 2005 is starting to act very strange when I debug the project. For instance, if i set a break point, I often can't expand an...
0
7228
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7058
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5635
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.