473,480 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

string question

I have gone over allot of the samples and documentation on the internet on
strings. I am not seeing a good example of a function or sub to remove all
characters to right or left of a given character. The ones I see I don't
know how to implement.

I want to take the following

c:\temp\otherTemp
c:\temp\2ndTemp

and just returns from what follow after the last"\"

otherTemp
2ndTemp

I see the String.TrimStart Method...but i cant figure out how to implement
it.

thanks
May 31 '07 #1
5 862
Have you tried Path.GetFileName?
shane wrote:
I have gone over allot of the samples and documentation on the internet on
strings. I am not seeing a good example of a function or sub to remove all
characters to right or left of a given character. The ones I see I don't
know how to implement.

I want to take the following

c:\temp\otherTemp
c:\temp\2ndTemp

and just returns from what follow after the last"\"

otherTemp
2ndTemp

I see the String.TrimStart Method...but i cant figure out how to implement
it.

thanks

May 31 '07 #2

Hi

Dim sPath As String = "c:\temp\otherTemp"
Dim sResult=sPath.Substring(sPath.LastIndexOf("\") + 1)

Mex
"shane" <az***@hotmail.comwrote in message
news:uw**************@TK2MSFTNGP06.phx.gbl...
>I have gone over allot of the samples and documentation on the internet on
strings. I am not seeing a good example of a function or sub to remove all
characters to right or left of a given character. The ones I see I don't
know how to implement.

I want to take the following

c:\temp\otherTemp
c:\temp\2ndTemp

and just returns from what follow after the last"\"

otherTemp
2ndTemp

I see the String.TrimStart Method...but i cant figure out how to implement
it.

thanks

May 31 '07 #3
shane wrote:
I want to take the following
c:\temp\otherTemp
c:\temp\2ndTemp
and just returns from what follow after the last"\"
Since you're working with file system Paths, how about using the Path
class in System.IO?

Imports System.IO

? Path.GetFilename( "c:\temp\otherTemp" )

Or, if you're determined to do it the String way ...

Dim s as String = "c:\temp\otherTemp"
? s.SubString( s.LastIndexof( "\" ) + 1 )

.... but don't be surprised if you get odd results from this, from time
to time. The methods in Path are far more tolerant of dodgy-looking
paths.

HTH,
Phill W.
May 31 '07 #4

"shane" <az***@hotmail.comwrote in message
news:uw**************@TK2MSFTNGP06.phx.gbl...
>I have gone over allot of the samples and documentation on the internet on
strings. I am not seeing a good example of a function or sub to remove all
characters to right or left of a given character. The ones I see I don't
know how to implement.

I want to take the following

c:\temp\otherTemp
c:\temp\2ndTemp

and just returns from what follow after the last"\"

otherTemp
2ndTemp

I see the String.TrimStart Method...but i cant figure out how to implement
it.

thanks
Since you asked for a String solution..
broken down into steps:
Dim s as String = "c:\temp\otherTemp"
Dim pos as Integer = s.lastIndexOf("\") + 1
Dim strFileName as String = s.substring(pos )

You may combine a couple of steps
HTH
Jun 1 '07 #5
thanks a million guys..That worked great, but I will look at your other
suggestions . :)
"Hal Rosser" <hm******@bellsouth.netwrote in message
news:JG******************@bignews6.bellsouth.net.. .
>
"shane" <az***@hotmail.comwrote in message
news:uw**************@TK2MSFTNGP06.phx.gbl...
>>I have gone over allot of the samples and documentation on the internet on
strings. I am not seeing a good example of a function or sub to remove all
characters to right or left of a given character. The ones I see I don't
know how to implement.

I want to take the following

c:\temp\otherTemp
c:\temp\2ndTemp

and just returns from what follow after the last"\"

otherTemp
2ndTemp

I see the String.TrimStart Method...but i cant figure out how to
implement it.

thanks
Since you asked for a String solution..
broken down into steps:
Dim s as String = "c:\temp\otherTemp"
Dim pos as Integer = s.lastIndexOf("\") + 1
Dim strFileName as String = s.substring(pos )

You may combine a couple of steps
HTH


Jun 1 '07 #6

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

Similar topics

2
1448
by: sparks | last post by:
I know this is a stupid question but I can't find the answer. Please tell me where to find reference to this so I can print it out and staple it to my head.. dim I as integer dim missedstr as...
5
3007
by: John Baro | last post by:
I have a richtextbox which I want the "literal" rtf of. richtextbox.rtf returns {\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033\\uc1 }\r\n\0 when i put this into a string I get...
5
12440
by: Dave | last post by:
I'm receiving info from a com port into a string. I gradually process the string which constantly shortens it. The question is how long can a string be before I need to write some info to disk...
32
14756
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
2
8535
by: Dan Schumm | last post by:
I'm relatively new to regular expressions and was looking for some help on a problem that I need to solve. Basically, given an HTML string, I need to highlight certain words within the text of the...
11
17617
by: Zordiac | last post by:
How do I dynamically populate a string array? I hope there is something obvious that I'm missing here Option Strict On dim s() as string dim sTmp as string = "test" dim i as integer ...
53
4011
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
6
2191
by: tommaso.gastaldi | last post by:
Hi, does anybody know a speedy analog of IsNumeric() to check for strings/chars. I would like to check if an Object can be treated as a string before using a Cstr(), clearly avoiding the time...
39
2867
by: sucaba.r | last post by:
I don't know if this is a unique problem, or I'm going about it the wrong way. I currently connect to one of our SQL servers via a priviliged account (by using RUNAS). Works with no problem. I...
7
7792
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}"...
0
7055
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
6920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7059
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,...
1
6758
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
7010
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
4499
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
3003
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1311
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
572
muto222
php
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.