Stripping letters from filename

  • Thread starter Thread starter Benway
  • Start date Start date
B

Benway

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
 
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 said:
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.
 
Phill said:
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
 
Benway said:
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
 
Benway said:
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.
 
Benway said:
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
 
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?

Look up the documentation for the String class (Google for: .net
string class). I bet you will find a method called 'replace'.
 
Phill said:
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
 
Back
Top