473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Stripping letters from filename

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
7 1369
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ralph Freshour | last post by:
I'm taking text from a textarea object and want to strip out characters other than A-Za-z0-9 before I send the data to MySQL table - is there a function I can use to do this in PHP? Thanks...
15
by: Jeff North | last post by:
Hi, I'm using a control called HTMLArea which allows a person to enter text and converts the format instructions to html tags. Most of my users know nothing about html so this is perfect for my...
7
by: Raj | last post by:
Hi I was hoping someone could suggest a simple way of stripping non-numeric data from a string of numbers. For example, if I have "ADB12458789\n" I would like to remove the letters and the...
2
by: Mikey | last post by:
Sample VB .NET source code to create mailing labels or customized letters using MS Word MailMerge This VB .NET source code will start MS Word and call methods and set properties in MS Word to...
7
by: Edward Elliott | last post by:
I'm looking for the "best" way to strip a large set of chars from a filename string (my definition of best usually means succinct and readable). I only want to allow alphanumeric chars, dashes,...
2
by: Greg Larsen | last post by:
I have a string that contains both the filename and the directory. Something like "c:\temp\test.txt". I need a process that will take this string and return only the file portion "text.txt". How...
0
by: euniceno1 | last post by:
the problem is to count the letters and sequence from a file. the fist thing of my code is to read file and in the main function i create is to count the characters and sequence by using 2 dimension...
2
by: dpreston74 | last post by:
Hello forum. I need to learn how write a SQL script to strip 0s from data and strip alpha letters from alpha numeric data. e.g. I get data like 054, 006, 903, for a dept number. I need to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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,...
0
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.