473,606 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
+ 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\otherTe mp
c:\temp\2ndTemp

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

otherTemp
2ndTemp

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

thanks
May 31 '07 #1
5 867
Have you tried Path.GetFileNam e?
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\otherTe mp
c:\temp\2ndTemp

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

otherTemp
2ndTemp

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

thanks

May 31 '07 #2

Hi

Dim sPath As String = "c:\temp\otherT emp"
Dim sResult=sPath.S ubstring(sPath. LastIndexOf("\" ) + 1)

Mex
"shane" <az***@hotmail. comwrote in message
news:uw******** ******@TK2MSFTN GP06.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\otherTe mp
c:\temp\2ndTemp

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

otherTemp
2ndTemp

I see the String.TrimStar t 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\otherTe mp
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.GetFilenam e( "c:\temp\otherT emp" )

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

Dim s as String = "c:\temp\otherT emp"
? 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******** ******@TK2MSFTN GP06.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\otherTe mp
c:\temp\2ndTemp

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

otherTemp
2ndTemp

I see the String.TrimStar t 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\otherT emp"
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******@bells outh.netwrote in message
news:JG******** **********@bign ews6.bellsouth. net...
>
"shane" <az***@hotmail. comwrote in message
news:uw******** ******@TK2MSFTN GP06.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\otherT emp
c:\temp\2ndTem p

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

otherTemp
2ndTemp

I see the String.TrimStar t 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\otherT emp"
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
1454
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 string For i = 1 To 17 'If IsNull("question" & i & ".Value") Then missedstr = missedstr & " question " & i
5
3014
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 "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033\\uc1 }\r\n\0" I want this to be @"{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033\\uc1 }\r\n\0" to treat the escape characters as literals
5
12454
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 inorder not to loose any information?
32
14814
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 ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
2
8549
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 string. I had it working somewhat, but ran into problems if one of the highlighted words could also be part of an HTML tag (such as 'Table' or 'Border'). What I need is the regex to find the word, but ignore any words that fall between an HTML...
11
17636
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 s(i)=new string(test) Above line gives - error implicit conversion string to 1-dim array of
53
4046
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
2201
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 and resource consuming Try... Catch, which in iterative processing is totally unacceptable. -tom
39
2887
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 now need the ability to connect to the same SQL server using ASP. I have the following connect string, but I'm not sure how to specify the domain in the string, or is there some other way? <% Set demoConn =...
7
7805
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}" As far as I know yet -- hence this question -- there is no 'one solution fits all', but instead there are several parts that have to be put together to check. What I have so far is, and would like as much feedback as possible to ensure I've...
0
8024
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
7959
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8449
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
8432
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
6781
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5466
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
3942
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
2451
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
0
1305
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.