473,835 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String help

Hi all,

I have a variable called root which contains
(E:\Web\Website s\fileBrowse\) and then I have a variable called path
which uses root, and adds directories on to it (this is part of a file
browser i've built). I'm trying to simply remove the root string from
the path string, so for example below:

root = E:\Web\Websites \fileBrowse\
path = E:\Web\Websites \fileBrowse\ima ges\

the result I want should be "images\"

I'm attempting to do this using the following line of code:

blah = path.TrimStart( root.ToCharArra y());

This isn't working though. Instead of getting "images\", i'm getting
"ages\". I've tried trimming using a start and end element of the char
array but I still get the same result. It seems that for some reason
the "\" which is trimmed at the end of root is taken as a control
character and so takes the proceding two characters too "im".

Has anyone got any idea how to stop this happening? I'm hoping it's
something simple which i'm overlooking.

Any help would be appreciated.

Aug 2 '06 #1
16 1599
Dim root As String = "E:\Web\Website s\fileBrowse\"
Dim path As String = "E:\Web\Website s\fileBrowse\im ages\"

MessageBox.Show (Replace(path, root, ""))

- Augustin

"^MisterJin go^" wrote:
Hi all,

I have a variable called root which contains
(E:\Web\Website s\fileBrowse\) and then I have a variable called path
which uses root, and adds directories on to it (this is part of a file
browser i've built). I'm trying to simply remove the root string from
the path string, so for example below:

root = E:\Web\Websites \fileBrowse\
path = E:\Web\Websites \fileBrowse\ima ges\

the result I want should be "images\"

I'm attempting to do this using the following line of code:

blah = path.TrimStart( root.ToCharArra y());

This isn't working though. Instead of getting "images\", i'm getting
"ages\". I've tried trimming using a start and end element of the char
array but I still get the same result. It seems that for some reason
the "\" which is trimmed at the end of root is taken as a control
character and so takes the proceding two characters too "im".

Has anyone got any idea how to stop this happening? I'm hoping it's
something simple which i'm overlooking.

Any help would be appreciated.

Aug 2 '06 #2
Interesting..

Without looking much into it, you might be better off simply doing:

path.Substring( root.Length); (which I tested and it works).

I'll need to look more into why TrimStart() is behaving that way..

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"^MisterJin go^" <mi*********@gm ail.comwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
Hi all,

I have a variable called root which contains
(E:\Web\Website s\fileBrowse\) and then I have a variable called path
which uses root, and adds directories on to it (this is part of a file
browser i've built). I'm trying to simply remove the root string from
the path string, so for example below:

root = E:\Web\Websites \fileBrowse\
path = E:\Web\Websites \fileBrowse\ima ges\

the result I want should be "images\"

I'm attempting to do this using the following line of code:

blah = path.TrimStart( root.ToCharArra y());

This isn't working though. Instead of getting "images\", i'm getting
"ages\". I've tried trimming using a start and end element of the char
array but I still get the same result. It seems that for some reason
the "\" which is trimmed at the end of root is taken as a control
character and so takes the proceding two characters too "im".

Has anyone got any idea how to stop this happening? I'm hoping it's
something simple which i'm overlooking.

Any help would be appreciated.

Aug 2 '06 #3
Augustin Prasanna wrote:
Dim root As String = "E:\Web\Website s\fileBrowse\"
Dim path As String = "E:\Web\Website s\fileBrowse\im ages\"

MessageBox.Show (Replace(path, root, ""))

- Augustin
Hi Augustin,

I'm not very up on VB, so could you tell me what the Replace is a
method of? I can find string.Replace. But that only takes 2 single
chars. Also MessageBoax isn't availible to ASP.Net pages is it?
Sorry if i'm being dense here.

Aug 2 '06 #4
Oh..I got it :)

TrimStart removes all references to any array of the characters you pass in.

So if you did:

"abcd".TrimStar t('d','c','b',' a');

it would remove everything - ie, they don't need to be in order.

You'll notice that the 'i' is being trimmed, but that's because you're
passing it an 'i' as a character to trim. It keeps going, removing ANY
character you passed in (in any order) until it finds one that wasn't passed
in and stops.

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
"^MisterJin go^" <mi*********@gm ail.comwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
Hi all,

I have a variable called root which contains
(E:\Web\Website s\fileBrowse\) and then I have a variable called path
which uses root, and adds directories on to it (this is part of a file
browser i've built). I'm trying to simply remove the root string from
the path string, so for example below:

root = E:\Web\Websites \fileBrowse\
path = E:\Web\Websites \fileBrowse\ima ges\

the result I want should be "images\"

I'm attempting to do this using the following line of code:

blah = path.TrimStart( root.ToCharArra y());

This isn't working though. Instead of getting "images\", i'm getting
"ages\". I've tried trimming using a start and end element of the char
array but I still get the same result. It seems that for some reason
the "\" which is trimmed at the end of root is taken as a control
character and so takes the proceding two characters too "im".

Has anyone got any idea how to stop this happening? I'm hoping it's
something simple which i'm overlooking.

Any help would be appreciated.

Aug 2 '06 #5
Karl Seguin [MVP] wrote:
Interesting..

Without looking much into it, you might be better off simply doing:

path.Substring( root.Length); (which I tested and it works).

I'll need to look more into why TrimStart() is behaving that way..

Karl

Hi Karl,

That works perfectly, thanks. I've no idea why TrimStart is behaving
that way :\.

Aug 2 '06 #6
Karl Seguin [MVP] wrote:
Oh..I got it :)

TrimStart removes all references to any array of the characters you pass in.

So if you did:

"abcd".TrimStar t('d','c','b',' a');

it would remove everything - ie, they don't need to be in order.

You'll notice that the 'i' is being trimmed, but that's because you're
passing it an 'i' as a character to trim. It keeps going, removing ANY
character you passed in (in any order) until it finds one that wasn't passed
in and stops.

Karl

--
http://www.openmymind.net/
http://www.codebetter.com/
Ah, I didn't know this :). I thought it just trimmed them in the order
passed, up until the last element of the char array.

Aug 2 '06 #7
Replace function will accept 3 parameters.

Replace (expression, find, replace)

for e.g replace ('test', 's', 'e') will return 'teet' because 's' will be
replaced with 'e'.

I hope this helps you.

MessageBox is for testing purpose. it can be used in windows app. you can
try 'Response.Write ' to test the output

"^MisterJin go^" wrote:
Hi Augustin,

I'm not very up on VB, so could you tell me what the Replace is a
method of? I can find string.Replace. But that only takes 2 single
chars. Also MessageBoax isn't availible to ASP.Net pages is it?
Sorry if i'm being dense here.

Aug 2 '06 #8
Augustin Prasanna wrote:
Replace function will accept 3 parameters.

Replace (expression, find, replace)

for e.g replace ('test', 's', 'e') will return 'teet' because 's' will be
replaced with 'e'.

I hope this helps you.

MessageBox is for testing purpose. it can be used in windows app. you can
try 'Response.Write ' to test the output
Is the Replace function VB only? I can't seem to find a standalone
replace function in C#.

Aug 2 '06 #9
The replace function is available on the string variable you have.
Here's a short sample. Hope this helps.

string root = @"E:\Web\Websit es\fileBrowse\" ;
string path = @"E:\Web\Websit es\fileBrowse\i mages\";

// You can use Replace this way
path = path.Replace(ro ot, "");
Response.Write( path);

^MisterJingo^ wrote:
Augustin Prasanna wrote:
Replace function will accept 3 parameters.

Replace (expression, find, replace)

for e.g replace ('test', 's', 'e') will return 'teet' because 's' will be
replaced with 'e'.

I hope this helps you.

MessageBox is for testing purpose. it can be used in windows app. you can
try 'Response.Write ' to test the output

Is the Replace function VB only? I can't seem to find a standalone
replace function in C#.
Aug 2 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2899
by: Helmut Jarausch | last post by:
Hi, entering help('rstrip') or help('ljust') into IDLE's shell window I only get no Python documentation found ...
3
13018
by: Imran Aziz | last post by:
Hello All, I am getting the following error on our production server, and I dont get the same error on the development box. Unable to cast object of type 'System.Byte' to type 'System.String'. here is the code that I used to create a table and then add columns to it later, later I populate the rows in the table.
5
2623
by: Sia Jai Sung | last post by:
Hi, I have a class that I modify from a sample program, like below ========================================== Imports System Imports System.Web.UI Imports System.Security.Cryptography public Class CSoccerichCommonFunc
6
6123
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or more minutes. 'REMOVE DUBLICATED VALUE FROM ARRAY +++++++++++++++++ Dim col As New Scripting.Dictionary Dim ii As Integer = 0
6
3694
by: Calros Lo | last post by:
Dear all: I develop a programe that need when I get a string , such as "123" or "ABC",if I get string "123" and the system will help me to create new string "124" , if I get string "ABC" and the system will help me to create new string "ABD" , could somebody can help me how to programe it , thank you very much. I don't know to how to covert string as ASCII and add integer value and covert the integer back to string, hope can support me...
5
471
by: Joe Nova | last post by:
I'm a C++ noob and I need a little help manipulating strings. I've got a program that takes an expression in the form: "operand1 operator operand2" I'd like to: 1. Find the total length of the string
9
3880
by: MikeB | last post by:
Hi, I'd appreciate some help, please. I'm writing a VS2005 VB project for school and one of the requirements is that every screen should have a "Help" button. I could do it by writing a clumsy case statement like this: sub showHelp(byval frm as String) Select Case (frm) Case "Form1" dim help as new Form1
8
4995
by: Lucky | last post by:
hi guys! back again with another query. the problem is like this. i want to print a line like this: "---------------------------------------------" the easiest way is to simply assign it to string and print it. but i want to use the String.Format() method if possible to do it.
13
3180
by: mac | last post by:
Hi, I'm trying to write a fibonacci recursive function that will return the fibonacci string separated by comma. The problem sounds like this: ------------- Write a recursive function that creates a character string containing the first n Fibonacci numbers - F(n) = F(n - 1) + F(n - 2), F(0) = F(1) = 1 -, separated by comma. n should be given as an argument to the program. The recursive function should only take one parameter, n, and...
37
1868
by: xyz | last post by:
I have a string 16:23:18.659343 131.188.37.230.22 131.188.37.59.1398 tcp 168 for example lets say for the above string 16:23:18.659343 -- time 131.188.37.230 -- srcaddress 22 --srcport 131.188.37.59 --destaddress 1398 --destport tcp --protocol
0
9808
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10812
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10523
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10235
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6966
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5638
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4434
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 we have to send another system
2
3995
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3089
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.