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

IsNumeric question

P: n/a
Hi,
I am trying to check a string to see if it's first 3 characters are numeric
and if they are, to replace those 3 characters with something else.

I've tried this but nothing happens...

newname = Replace(newname, VB.Left(newname, 3) = "101-", "101. ")

The method I've been using up to now is very drawn out and too long and I
need a more efficient way of doing it.
This is what I've beeni using...

If VB.Left(newname, 3) = "01-" Or VB.Left(newname, 3) = "02-" _
Or VB.Left(newname, 3) = "03-" Or VB.Left(newname, 3) = "04-" _
Or VB.Left(newname, 3) = "05-" Or VB.Left(newname, 3) = "06-" _
Or VB.Left(newname, 3) = "07-" Or VB.Left(newname, 3) = "08-" _
Or VB.Left(newname, 3) = "09-" Or VB.Left(newname, 3) = "10-" Then
newname = Replace(newname, "01-", "01. ")
newname = Replace(newname, "02-", "02. ")
newname = Replace(newname, "03-", "03. ")
newname = Replace(newname, "04-", "04. ")
newname = Replace(newname, "05-", "05. ")
newname = Replace(newname, "06-", "06. ")
newname = Replace(newname, "07-", "07. ")
newname = Replace(newname, "08-", "08. ")
newname = Replace(newname, "09-", "09. ")
newname = Replace(newname, "10-", "10. ")
End If

Any ideas?
Cheers,
Paul
Oct 30 '06 #1
Share this Question
Share on Google+
12 Replies


P: n/a
can't you just check for the character "-" and replace it with a "." ?
"Paul" <ia*@home.co.ukschreef in bericht
news:oL********************@pipex.net...
Hi,
I am trying to check a string to see if it's first 3 characters are
numeric and if they are, to replace those 3 characters with something
else.

I've tried this but nothing happens...

newname = Replace(newname, VB.Left(newname, 3) = "101-", "101. ")

The method I've been using up to now is very drawn out and too long and I
need a more efficient way of doing it.
This is what I've beeni using...

If VB.Left(newname, 3) = "01-" Or VB.Left(newname, 3) = "02-" _
Or VB.Left(newname, 3) = "03-" Or VB.Left(newname, 3) = "04-" _
Or VB.Left(newname, 3) = "05-" Or VB.Left(newname, 3) = "06-" _
Or VB.Left(newname, 3) = "07-" Or VB.Left(newname, 3) = "08-" _
Or VB.Left(newname, 3) = "09-" Or VB.Left(newname, 3) = "10-" Then
newname = Replace(newname, "01-", "01. ")
newname = Replace(newname, "02-", "02. ")
newname = Replace(newname, "03-", "03. ")
newname = Replace(newname, "04-", "04. ")
newname = Replace(newname, "05-", "05. ")
newname = Replace(newname, "06-", "06. ")
newname = Replace(newname, "07-", "07. ")
newname = Replace(newname, "08-", "08. ")
newname = Replace(newname, "09-", "09. ")
newname = Replace(newname, "10-", "10. ")
End If

Any ideas?
Cheers,
Paul

Oct 30 '06 #2

P: n/a
I have no idea what you are trying to say, but I'll still try to answer
you.

Are you just trying to replace the first hyphen with a period? If so
just do this:

newname = newname.Substring(0, 3) & Replace(newname.Substring(3, 1),
"-", ".") & newname.Substring(4, newname.Length - 4)

If you need the first 3 characters to be numeric then wrap the above in
an if...then test

i.e.

If IsNumeric(newname.Substring(1, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3,
1), "-", ".") & newname.Substring(4, newname.Length - 4)
MsgBox(newname)
End If

Thanks,

Seth Rowe
Paul wrote:
Hi,
I am trying to check a string to see if it's first 3 characters are numeric
and if they are, to replace those 3 characters with something else.

I've tried this but nothing happens...

newname = Replace(newname, VB.Left(newname, 3) = "101-", "101. ")

The method I've been using up to now is very drawn out and too long and I
need a more efficient way of doing it.
This is what I've beeni using...

If VB.Left(newname, 3) = "01-" Or VB.Left(newname, 3) = "02-" _
Or VB.Left(newname, 3) = "03-" Or VB.Left(newname, 3) = "04-" _
Or VB.Left(newname, 3) = "05-" Or VB.Left(newname, 3) = "06-" _
Or VB.Left(newname, 3) = "07-" Or VB.Left(newname, 3) = "08-" _
Or VB.Left(newname, 3) = "09-" Or VB.Left(newname, 3) = "10-" Then
newname = Replace(newname, "01-", "01. ")
newname = Replace(newname, "02-", "02. ")
newname = Replace(newname, "03-", "03. ")
newname = Replace(newname, "04-", "04. ")
newname = Replace(newname, "05-", "05. ")
newname = Replace(newname, "06-", "06. ")
newname = Replace(newname, "07-", "07. ")
newname = Replace(newname, "08-", "08. ")
newname = Replace(newname, "09-", "09. ")
newname = Replace(newname, "10-", "10. ")
End If

Any ideas?
Cheers,
Paul
Oct 30 '06 #3

P: n/a
You could also try using the Regular Expression (Regex) features, as they
would let you examine the source string using wildcard-like patterns.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
Hi,
I am trying to check a string to see if it's first 3 characters are
numeric
and if they are, to replace those 3 characters with something else.
I've tried this but nothing happens...

newname = Replace(newname, VB.Left(newname, 3) = "101-", "101. ")

The method I've been using up to now is very drawn out and too long
and I
need a more efficient way of doing it.
This is what I've beeni using...
If VB.Left(newname, 3) = "01-" Or VB.Left(newname, 3) = "02-" _
Or VB.Left(newname, 3) = "03-" Or VB.Left(newname, 3) = "04-" _
Or VB.Left(newname, 3) = "05-" Or VB.Left(newname, 3) = "06-" _
Or VB.Left(newname, 3) = "07-" Or VB.Left(newname, 3) = "08-" _
Or VB.Left(newname, 3) = "09-" Or VB.Left(newname, 3) = "10-" Then
newname = Replace(newname, "01-", "01. ")
newname = Replace(newname, "02-", "02. ")
newname = Replace(newname, "03-", "03. ")
newname = Replace(newname, "04-", "04. ")
newname = Replace(newname, "05-", "05. ")
newname = Replace(newname, "06-", "06. ")
newname = Replace(newname, "07-", "07. ")
newname = Replace(newname, "08-", "08. ")
newname = Replace(newname, "09-", "09. ")
newname = Replace(newname, "10-", "10. ")
End If
Any ideas?
Cheers,
Paul

Oct 30 '06 #4

P: n/a
Paul,

The substring is your friend.

If IsNumeric("123A".Substring(0, 3)) Then
MessageBox.Show("Yes I am")
End If

I hope this helps,

Cor

"Paul" <ia*@home.co.ukschreef in bericht
news:oL********************@pipex.net...
Hi,
I am trying to check a string to see if it's first 3 characters are
numeric and if they are, to replace those 3 characters with something
else.

I've tried this but nothing happens...

newname = Replace(newname, VB.Left(newname, 3) = "101-", "101. ")

The method I've been using up to now is very drawn out and too long and I
need a more efficient way of doing it.
This is what I've beeni using...

If VB.Left(newname, 3) = "01-" Or VB.Left(newname, 3) = "02-" _
Or VB.Left(newname, 3) = "03-" Or VB.Left(newname, 3) = "04-" _
Or VB.Left(newname, 3) = "05-" Or VB.Left(newname, 3) = "06-" _
Or VB.Left(newname, 3) = "07-" Or VB.Left(newname, 3) = "08-" _
Or VB.Left(newname, 3) = "09-" Or VB.Left(newname, 3) = "10-" Then
newname = Replace(newname, "01-", "01. ")
newname = Replace(newname, "02-", "02. ")
newname = Replace(newname, "03-", "03. ")
newname = Replace(newname, "04-", "04. ")
newname = Replace(newname, "05-", "05. ")
newname = Replace(newname, "06-", "06. ")
newname = Replace(newname, "07-", "07. ")
newname = Replace(newname, "08-", "08. ")
newname = Replace(newname, "09-", "09. ")
newname = Replace(newname, "10-", "10. ")
End If

Any ideas?
Cheers,
Paul

Oct 30 '06 #5

P: n/a
If IsNumeric(newname.Substring(1, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3,
1), "-", ".") & newname.Substring(4, newname.Length - 4)
MsgBox(newname)
End If
Replace that with this:

If IsNumeric(newname.Substring(0, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3,
1), "-", ".") & newname.Substring(4, newname.Length - 4)
MsgBox(newname)
End If

Thanks,

Seth Rowe
rowe_newsgroups wrote:
I have no idea what you are trying to say, but I'll still try to answer
you.

Are you just trying to replace the first hyphen with a period? If so
just do this:

newname = newname.Substring(0, 3) & Replace(newname.Substring(3, 1),
"-", ".") & newname.Substring(4, newname.Length - 4)

If you need the first 3 characters to be numeric then wrap the above in
an if...then test

i.e.

If IsNumeric(newname.Substring(1, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3,
1), "-", ".") & newname.Substring(4, newname.Length - 4)
MsgBox(newname)
End If

Thanks,

Seth Rowe
Paul wrote:
Hi,
I am trying to check a string to see if it's first 3 characters are numeric
and if they are, to replace those 3 characters with something else.

I've tried this but nothing happens...

newname = Replace(newname, VB.Left(newname, 3) = "101-", "101. ")

The method I've been using up to now is very drawn out and too long and I
need a more efficient way of doing it.
This is what I've beeni using...

If VB.Left(newname, 3) = "01-" Or VB.Left(newname, 3) = "02-" _
Or VB.Left(newname, 3) = "03-" Or VB.Left(newname, 3) = "04-" _
Or VB.Left(newname, 3) = "05-" Or VB.Left(newname, 3) = "06-" _
Or VB.Left(newname, 3) = "07-" Or VB.Left(newname, 3) = "08-" _
Or VB.Left(newname, 3) = "09-" Or VB.Left(newname, 3) = "10-" Then
newname = Replace(newname, "01-", "01. ")
newname = Replace(newname, "02-", "02. ")
newname = Replace(newname, "03-", "03. ")
newname = Replace(newname, "04-", "04. ")
newname = Replace(newname, "05-", "05. ")
newname = Replace(newname, "06-", "06. ")
newname = Replace(newname, "07-", "07. ")
newname = Replace(newname, "08-", "08. ")
newname = Replace(newname, "09-", "09. ")
newname = Replace(newname, "10-", "10. ")
End If

Any ideas?
Cheers,
Paul
Oct 30 '06 #6

P: n/a
Paul wrote:
Hi,
I am trying to check a string to see if it's first 3 characters are numeric
and if they are, to replace those 3 characters with something else.

I've tried this but nothing happens...

newname = Replace(newname, VB.Left(newname, 3) = "101-", "101. ")
<snip>

You're asking VB to replace all occurrences of the string "false" by
"101.". That's because the expression VB.Left(newname, 3) = "101-" will
always return False (even though newname actually begins with "101-").
I'm sure it's not what you want.

What it seems you want is to replace the given prefix ("101-") by
another one... one that preserves the first two (or three?) integers
and replaces only the separator (from "-" to ".")

One possible approach could be:

<aircode>
Dim Sz as Integer = 3 'Change this to 2, for names like "10-..."
Dim Test As Integer
Dim Prefix As String = newname.Substring(0, Sz)
If newname(Sz) = "-" AndAlso Integer.TryParse(Prefix, Test) Then
newname = Prefix & "-" & newname.Substring(Sz+1)
End If
</aircode>

HTH.

Regards,

Branco.

Oct 30 '06 #7

P: n/a
I apoligise for not explaining myself but whilst writing the post I
accidently pressed the Alt+S key and sent the unfinished message!

Despite this your answer is working but strangely, only partly.

If I use the code as you gave it me, it works fine and replaces the "-" with
a "." but if I alter the code to change "_" to "." it strangely replaces the
"_" with a space instead of a "."
Some strings I have need the "-" replacing and some need the "_" replacing.

So to clarify, if I use the code as you gave it me the string ends up like
this...
"101.this_is_the_filename.mp3" <--works fine

But if I change the code to replace the "_" with a "." I get...
"101 this_is_the_filename.mp3" <--hmm, I get a space instead of a "."

Any ideas why its doing that?

Cheers,
Paul
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11*********************@f16g2000cwb.googlegro ups.com...
>I have no idea what you are trying to say, but I'll still try to answer
you.

Are you just trying to replace the first hyphen with a period? If so
just do this:

newname = newname.Substring(0, 3) & Replace(newname.Substring(3, 1),
"-", ".") & newname.Substring(4, newname.Length - 4)

If you need the first 3 characters to be numeric then wrap the above in
an if...then test

i.e.

If IsNumeric(newname.Substring(1, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3,
1), "-", ".") & newname.Substring(4, newname.Length - 4)
MsgBox(newname)
End If

Thanks,

Seth Rowe
Paul wrote:
>Hi,
I am trying to check a string to see if it's first 3 characters are
numeric
and if they are, to replace those 3 characters with something else.

I've tried this but nothing happens...

newname = Replace(newname, VB.Left(newname, 3) = "101-", "101. ")

The method I've been using up to now is very drawn out and too long and I
need a more efficient way of doing it.
This is what I've beeni using...

If VB.Left(newname, 3) = "01-" Or VB.Left(newname, 3) = "02-" _
Or VB.Left(newname, 3) = "03-" Or VB.Left(newname, 3) = "04-" _
Or VB.Left(newname, 3) = "05-" Or VB.Left(newname, 3) = "06-" _
Or VB.Left(newname, 3) = "07-" Or VB.Left(newname, 3) = "08-" _
Or VB.Left(newname, 3) = "09-" Or VB.Left(newname, 3) = "10-" Then
newname = Replace(newname, "01-", "01. ")
newname = Replace(newname, "02-", "02. ")
newname = Replace(newname, "03-", "03. ")
newname = Replace(newname, "04-", "04. ")
newname = Replace(newname, "05-", "05. ")
newname = Replace(newname, "06-", "06. ")
newname = Replace(newname, "07-", "07. ")
newname = Replace(newname, "08-", "08. ")
newname = Replace(newname, "09-", "09. ")
newname = Replace(newname, "10-", "10. ")
End If

Any ideas?
Cheers,
Paul

Oct 30 '06 #8

P: n/a
Please post the modified code you are using, including the string you
are trying to parse so we can see what you're doing.

Thanks,

Seth Rowe
Paul wrote:
I apoligise for not explaining myself but whilst writing the post I
accidently pressed the Alt+S key and sent the unfinished message!

Despite this your answer is working but strangely, only partly.

If I use the code as you gave it me, it works fine and replaces the "-" with
a "." but if I alter the code to change "_" to "." it strangely replaces the
"_" with a space instead of a "."
Some strings I have need the "-" replacing and some need the "_" replacing.

So to clarify, if I use the code as you gave it me the string ends up like
this...
"101.this_is_the_filename.mp3" <--works fine

But if I change the code to replace the "_" with a "." I get...
"101 this_is_the_filename.mp3" <--hmm, I get a space instead of a "."

Any ideas why its doing that?

Cheers,
Paul
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11*********************@f16g2000cwb.googlegro ups.com...
I have no idea what you are trying to say, but I'll still try to answer
you.

Are you just trying to replace the first hyphen with a period? If so
just do this:

newname = newname.Substring(0, 3) & Replace(newname.Substring(3, 1),
"-", ".") & newname.Substring(4, newname.Length - 4)

If you need the first 3 characters to be numeric then wrap the above in
an if...then test

i.e.

If IsNumeric(newname.Substring(1, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3,
1), "-", ".") & newname.Substring(4, newname.Length - 4)
MsgBox(newname)
End If

Thanks,

Seth Rowe
Paul wrote:
Hi,
I am trying to check a string to see if it's first 3 characters are
numeric
and if they are, to replace those 3 characters with something else.

I've tried this but nothing happens...

newname = Replace(newname, VB.Left(newname, 3) = "101-", "101. ")

The method I've been using up to now is very drawn out and too long and I
need a more efficient way of doing it.
This is what I've beeni using...

If VB.Left(newname, 3) = "01-" Or VB.Left(newname, 3) = "02-" _
Or VB.Left(newname, 3) = "03-" Or VB.Left(newname, 3) = "04-" _
Or VB.Left(newname, 3) = "05-" Or VB.Left(newname, 3) = "06-" _
Or VB.Left(newname, 3) = "07-" Or VB.Left(newname, 3) = "08-" _
Or VB.Left(newname, 3) = "09-" Or VB.Left(newname, 3) = "10-" Then
newname = Replace(newname, "01-", "01. ")
newname = Replace(newname, "02-", "02. ")
newname = Replace(newname, "03-", "03. ")
newname = Replace(newname, "04-", "04. ")
newname = Replace(newname, "05-", "05. ")
newname = Replace(newname, "06-", "06. ")
newname = Replace(newname, "07-", "07. ")
newname = Replace(newname, "08-", "08. ")
newname = Replace(newname, "09-", "09. ")
newname = Replace(newname, "10-", "10. ")
End If

Any ideas?
Cheers,
Paul
Oct 30 '06 #9

P: n/a
Sorry again, I posted my second message after you had provided me with the
replacement code.
It works fine now!

What I have now is...

If IsNumeric(newname.Substring(0, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3, 1),
"_", ". ") & newname.Substring(4, newname.Length - 4)
'MsgBox(newname)
End If

If IsNumeric(newname.Substring(0, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3, 1),
"-", ". ") & newname.Substring(4, newname.Length - 4)
'MsgBox(newname)
End If
Is there any way I can incorporate both into one routine? I mean replace
the "-" and the "_" to "." in one go?
Cheers,
Paul
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
>If IsNumeric(newname.Substring(1, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3,
1), "-", ".") & newname.Substring(4, newname.Length - 4)
MsgBox(newname)
End If

Replace that with this:

If IsNumeric(newname.Substring(0, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3,
1), "-", ".") & newname.Substring(4, newname.Length - 4)
MsgBox(newname)
End If

Thanks,

Seth Rowe
rowe_newsgroups wrote:
>I have no idea what you are trying to say, but I'll still try to answer
you.

Are you just trying to replace the first hyphen with a period? If so
just do this:

newname = newname.Substring(0, 3) & Replace(newname.Substring(3, 1),
"-", ".") & newname.Substring(4, newname.Length - 4)

If you need the first 3 characters to be numeric then wrap the above in
an if...then test

i.e.

If IsNumeric(newname.Substring(1, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3,
1), "-", ".") & newname.Substring(4, newname.Length - 4)
MsgBox(newname)
End If

Thanks,

Seth Rowe
Paul wrote:
Hi,
I am trying to check a string to see if it's first 3 characters are
numeric
and if they are, to replace those 3 characters with something else.

I've tried this but nothing happens...

newname = Replace(newname, VB.Left(newname, 3) = "101-", "101. ")

The method I've been using up to now is very drawn out and too long and
I
need a more efficient way of doing it.
This is what I've beeni using...

If VB.Left(newname, 3) = "01-" Or VB.Left(newname, 3) = "02-" _
Or VB.Left(newname, 3) = "03-" Or VB.Left(newname, 3) = "04-" _
Or VB.Left(newname, 3) = "05-" Or VB.Left(newname, 3) = "06-" _
Or VB.Left(newname, 3) = "07-" Or VB.Left(newname, 3) = "08-" _
Or VB.Left(newname, 3) = "09-" Or VB.Left(newname, 3) = "10-" Then
newname = Replace(newname, "01-", "01. ")
newname = Replace(newname, "02-", "02. ")
newname = Replace(newname, "03-", "03. ")
newname = Replace(newname, "04-", "04. ")
newname = Replace(newname, "05-", "05. ")
newname = Replace(newname, "06-", "06. ")
newname = Replace(newname, "07-", "07. ")
newname = Replace(newname, "08-", "08. ")
newname = Replace(newname, "09-", "09. ")
newname = Replace(newname, "10-", "10. ")
End If

Any ideas?
Cheers,
Paul

Oct 30 '06 #10

P: n/a
Sorry again, I posted my second message after you had provided me with the
replacement code.
Yeah, sorry about the typo in the first post - I tend to type before I
think sometimes :-)

Try this:

If IsNumeric(newname.Substring(0, 3)) Then
Dim temp As String = newname.Substring(3, 1)
If temp = "-" OrElse temp = "_" Then ' Add more OrElse statements
to replace other characters if required
newname = newname.Substring(0, 3) &
Replace(newname.Substring(3, 1), temp, ". ") & newname.Substring(4,
newname.Length - 4)
MsgBox(newname)
End If
End If
Thanks,

Seth Rowe
Paul wrote:
Sorry again, I posted my second message after you had provided me with the
replacement code.
It works fine now!

What I have now is...

If IsNumeric(newname.Substring(0, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3, 1),
"_", ". ") & newname.Substring(4, newname.Length - 4)
'MsgBox(newname)
End If

If IsNumeric(newname.Substring(0, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3, 1),
"-", ". ") & newname.Substring(4, newname.Length - 4)
'MsgBox(newname)
End If
Is there any way I can incorporate both into one routine? I mean replace
the "-" and the "_" to "." in one go?
Cheers,
Paul
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
If IsNumeric(newname.Substring(1, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3,
1), "-", ".") & newname.Substring(4, newname.Length - 4)
MsgBox(newname)
End If
Replace that with this:

If IsNumeric(newname.Substring(0, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3,
1), "-", ".") & newname.Substring(4, newname.Length - 4)
MsgBox(newname)
End If

Thanks,

Seth Rowe
rowe_newsgroups wrote:
I have no idea what you are trying to say, but I'll still try to answer
you.

Are you just trying to replace the first hyphen with a period? If so
just do this:

newname = newname.Substring(0, 3) & Replace(newname.Substring(3, 1),
"-", ".") & newname.Substring(4, newname.Length - 4)

If you need the first 3 characters to be numeric then wrap the above in
an if...then test

i.e.

If IsNumeric(newname.Substring(1, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3,
1), "-", ".") & newname.Substring(4, newname.Length - 4)
MsgBox(newname)
End If

Thanks,

Seth Rowe
Paul wrote:
Hi,
I am trying to check a string to see if it's first 3 characters are
numeric
and if they are, to replace those 3 characters with something else.

I've tried this but nothing happens...

newname = Replace(newname, VB.Left(newname, 3) = "101-", "101. ")

The method I've been using up to now is very drawn out and too long and
I
need a more efficient way of doing it.
This is what I've beeni using...

If VB.Left(newname, 3) = "01-" Or VB.Left(newname, 3) = "02-" _
Or VB.Left(newname, 3) = "03-" Or VB.Left(newname, 3) = "04-" _
Or VB.Left(newname, 3) = "05-" Or VB.Left(newname, 3) = "06-" _
Or VB.Left(newname, 3) = "07-" Or VB.Left(newname, 3) = "08-" _
Or VB.Left(newname, 3) = "09-" Or VB.Left(newname, 3) = "10-" Then
newname = Replace(newname, "01-", "01. ")
newname = Replace(newname, "02-", "02. ")
newname = Replace(newname, "03-", "03. ")
newname = Replace(newname, "04-", "04. ")
newname = Replace(newname, "05-", "05. ")
newname = Replace(newname, "06-", "06. ")
newname = Replace(newname, "07-", "07. ")
newname = Replace(newname, "08-", "08. ")
newname = Replace(newname, "09-", "09. ")
newname = Replace(newname, "10-", "10. ")
End If

Any ideas?
Cheers,
Paul
Oct 30 '06 #11

P: n/a
Perfect! Thanks so much

Seth the String Master!

Cheers,
Paul

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@e64g2000cwd.googlegr oups.com...
>Sorry again, I posted my second message after you had provided me with
the
replacement code.

Yeah, sorry about the typo in the first post - I tend to type before I
think sometimes :-)

Try this:

If IsNumeric(newname.Substring(0, 3)) Then
Dim temp As String = newname.Substring(3, 1)
If temp = "-" OrElse temp = "_" Then ' Add more OrElse statements
to replace other characters if required
newname = newname.Substring(0, 3) &
Replace(newname.Substring(3, 1), temp, ". ") & newname.Substring(4,
newname.Length - 4)
MsgBox(newname)
End If
End If
Thanks,

Seth Rowe
Paul wrote:
>Sorry again, I posted my second message after you had provided me with
the
replacement code.
It works fine now!

What I have now is...

If IsNumeric(newname.Substring(0, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3, 1),
"_", ". ") & newname.Substring(4, newname.Length - 4)
'MsgBox(newname)
End If

If IsNumeric(newname.Substring(0, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3, 1),
"-", ". ") & newname.Substring(4, newname.Length - 4)
'MsgBox(newname)
End If
Is there any way I can incorporate both into one routine? I mean replace
the "-" and the "_" to "." in one go?
Cheers,
Paul
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@k70g2000cwa.googleg roups.com...
>If IsNumeric(newname.Substring(1, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3,
1), "-", ".") & newname.Substring(4, newname.Length - 4)
MsgBox(newname)
End If

Replace that with this:

If IsNumeric(newname.Substring(0, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3,
1), "-", ".") & newname.Substring(4, newname.Length - 4)
MsgBox(newname)
End If

Thanks,

Seth Rowe
rowe_newsgroups wrote:
I have no idea what you are trying to say, but I'll still try to
answer
you.

Are you just trying to replace the first hyphen with a period? If so
just do this:

newname = newname.Substring(0, 3) & Replace(newname.Substring(3, 1),
"-", ".") & newname.Substring(4, newname.Length - 4)

If you need the first 3 characters to be numeric then wrap the above
in
an if...then test

i.e.

If IsNumeric(newname.Substring(1, 3)) Then
newname = newname.Substring(0, 3) & Replace(newname.Substring(3,
1), "-", ".") & newname.Substring(4, newname.Length - 4)
MsgBox(newname)
End If

Thanks,

Seth Rowe
Paul wrote:
Hi,
I am trying to check a string to see if it's first 3 characters are
numeric
and if they are, to replace those 3 characters with something else.

I've tried this but nothing happens...

newname = Replace(newname, VB.Left(newname, 3) = "101-", "101. ")

The method I've been using up to now is very drawn out and too long
and
I
need a more efficient way of doing it.
This is what I've beeni using...

If VB.Left(newname, 3) = "01-" Or VB.Left(newname, 3) = "02-" _
Or VB.Left(newname, 3) = "03-" Or VB.Left(newname, 3) = "04-" _
Or VB.Left(newname, 3) = "05-" Or VB.Left(newname, 3) = "06-" _
Or VB.Left(newname, 3) = "07-" Or VB.Left(newname, 3) = "08-" _
Or VB.Left(newname, 3) = "09-" Or VB.Left(newname, 3) = "10-"
Then
newname = Replace(newname, "01-", "01. ")
newname = Replace(newname, "02-", "02. ")
newname = Replace(newname, "03-", "03. ")
newname = Replace(newname, "04-", "04. ")
newname = Replace(newname, "05-", "05. ")
newname = Replace(newname, "06-", "06. ")
newname = Replace(newname, "07-", "07. ")
newname = Replace(newname, "08-", "08. ")
newname = Replace(newname, "09-", "09. ")
newname = Replace(newname, "10-", "10. ")
End If

Any ideas?
Cheers,
Paul

Oct 30 '06 #12

P: n/a
GS
use regex class
pattern like "?<prefx>(^\d\d\d[-])"
Caution, I writing from memory and have not check or test the above pattern.

check the built-in help for regex

"Joris De Groote" <jo************@skynet.bewrote in message
news:ef**************@TK2MSFTNGP04.phx.gbl...
can't you just check for the character "-" and replace it with a "." ?
"Paul" <ia*@home.co.ukschreef in bericht
news:oL********************@pipex.net...
Hi,
I am trying to check a string to see if it's first 3 characters are
numeric and if they are, to replace those 3 characters with something
else.

I've tried this but nothing happens...

newname = Replace(newname, VB.Left(newname, 3) = "101-", "101. ")

The method I've been using up to now is very drawn out and too long and
I
need a more efficient way of doing it.
This is what I've beeni using...

If VB.Left(newname, 3) = "01-" Or VB.Left(newname, 3) = "02-" _
Or VB.Left(newname, 3) = "03-" Or VB.Left(newname, 3) = "04-" _
Or VB.Left(newname, 3) = "05-" Or VB.Left(newname, 3) = "06-" _
Or VB.Left(newname, 3) = "07-" Or VB.Left(newname, 3) = "08-" _
Or VB.Left(newname, 3) = "09-" Or VB.Left(newname, 3) = "10-" Then
newname = Replace(newname, "01-", "01. ")
newname = Replace(newname, "02-", "02. ")
newname = Replace(newname, "03-", "03. ")
newname = Replace(newname, "04-", "04. ")
newname = Replace(newname, "05-", "05. ")
newname = Replace(newname, "06-", "06. ")
newname = Replace(newname, "07-", "07. ")
newname = Replace(newname, "08-", "08. ")
newname = Replace(newname, "09-", "09. ")
newname = Replace(newname, "10-", "10. ")
End If

Any ideas?
Cheers,
Paul


Nov 2 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.