By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,727 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,727 IT Pros & Developers. It's quick & easy.

Stripping letters from filename

P: n/a
Hey all,
I have a file name like Eng-Cat-01-01-01.txt. I need to do a loop that
starts stripping the letters from the front of this file name (which
I'll store as a variable) until it reaches the "Cat" part. So I would
have a variable "Cat-01-01-01.txt" that I can use to build up another
string.

Trouble is, I'm lost. Can't figure out how to do this in VB.net. Could
anyone point me in the right direction?

MANY thanks!

cm
Jul 18 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
You should probably convert the strings to all upper or all lower case, but
this is the idea.

Dim fn As String = "Eng-Cat-01-01-01.txt"
Console.Out.WriteLine(fn.Substring(fn.IndexOf("Cat ")))
"Benway" wrote:
Hey all,
I have a file name like Eng-Cat-01-01-01.txt. I need to do a loop that
starts stripping the letters from the front of this file name (which
I'll store as a variable) until it reaches the "Cat" part. So I would
have a variable "Cat-01-01-01.txt" that I can use to build up another
string.

Trouble is, I'm lost. Can't figure out how to do this in VB.net. Could
anyone point me in the right direction?

MANY thanks!

cm
Jul 18 '07 #2

P: n/a
Benway wrote:
I have a file name like Eng-Cat-01-01-01.txt. I need to do a loop
that starts stripping the letters from the front of this file name
(which I'll store as a variable) until it reaches the "Cat" part. So I
would have a variable "Cat-01-01-01.txt" that I can use to build up
another string.
Dim sFilename As String _
= "Eng-Cat-01-01-01.txt"
Dim iPos as Integer _
= sFilename.Indexof( "Cat" )

If iPos -1 Then
? sFilename.SubString( 0, iPos )
? sFilename.SubString( iPos + "Cat".Length() + 1 )

' or thereabouts ...

HTH,
Phill W.
Jul 18 '07 #3

P: n/a
Phill W. wrote:
Benway wrote:
>I have a file name like Eng-Cat-01-01-01.txt. I need to do a loop
that starts stripping the letters from the front of this file name
(which I'll store as a variable) until it reaches the "Cat" part. So
I would have a variable "Cat-01-01-01.txt" that I can use to build up
another string.

Dim sFilename As String _
= "Eng-Cat-01-01-01.txt"
Dim iPos as Integer _
= sFilename.Indexof( "Cat" )

If iPos -1 Then
? sFilename.SubString( 0, iPos )
? sFilename.SubString( iPos + "Cat".Length() + 1 )

' or thereabouts ...

HTH,
Phill W.
Thanks guys!

cm
Jul 18 '07 #4

P: n/a
Benway wrote:
Hey all,
I have a file name like Eng-Cat-01-01-01.txt. I need to do a loop
that starts stripping the letters from the front of this file name
(which I'll store as a variable) until it reaches the "Cat" part. So I
would have a variable "Cat-01-01-01.txt" that I can use to build up
another string.

Trouble is, I'm lost. Can't figure out how to do this in VB.net. Could
anyone point me in the right direction?

MANY thanks!

cm
Hey guys, one more thing you might be able to help with: I've got a
string of text in a label (about 10 or so letters). I need to search it
for "Mit" and replace it with "Cat". Any ideas?

Thanks again!

cm
Jul 19 '07 #5

P: n/a
Benway wrote:
I've got a string of text in a label (about 10 or so letters).
I need to search it for "Mit" and replace it with "Cat".
Any ideas?
So you want to "Replace" one value in a "String" with a different value?

There's a couple of keywords for you to look up ... ;-)

Do you have MSDN installed or do you have access to it on the Web?
Without it, you're going to be /really/ struggling to get to grips with
the Framework and all its classes and methods.

HTH,
Phill W.
Jul 19 '07 #6

P: n/a
Benway wrote:
Hey guys, one more thing you might be able to help with: I've got a
string of text in a label (about 10 or so letters). I need to search
it for "Mit" and replace it with "Cat". Any ideas?
SomeText=Replace(SomeText, "Mit", "Cat")

Andrew
Jul 19 '07 #7

P: n/a
Phill W. wrote:
Benway wrote:
>I've got a string of text in a label (about 10 or so letters).
I need to search it for "Mit" and replace it with "Cat". Any ideas?

So you want to "Replace" one value in a "String" with a different value?

There's a couple of keywords for you to look up ... ;-)

Do you have MSDN installed or do you have access to it on the Web?
Without it, you're going to be /really/ struggling to get to grips with
the Framework and all its classes and methods.

HTH,
Phill W.
Yeah, thanks for pointing me to Google. I'll check there more
thoroughly in the future.

cm
Jul 20 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.