473,386 Members | 1,726 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,386 software developers and data experts.

IsNumeric question

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

Similar topics

3
by: Lasse Edsvik | last post by:
Hello one question........ why does isnumeric return true? a="" if isnumeric(a) then response.write("test") end if empty isnt numerical is it??
8
by: eje | last post by:
IsNumeric(value) should return false if value "can not be successfully converted to a Double." Instead I get the following error message: "Input string was not in a correct format." I use the...
8
by: John Bowman | last post by:
Hello, Does anyone have a good/reliable approach to implementing an IsNumeric() method that accepts a string that may represent a numerical value (eg. such as some text retrieved from an XML...
3
by: Radith Silva | last post by:
Dear All; Thanx for helpt with previous question. Still learning?? FROM A VB 6.0 BOOK: any way; I have used IsNumeric function and check all namespace conflicts and all and nothing seems...
8
by: Dave | last post by:
I'm trying to import Microsoft.VisualBasic to use the IsNumeric function in my C# code but all I see is: Microsoft.VisualBasic.VBCodeProvider while using Intellisense... From samples shouldn't...
7
by: Nathan Truhan | last post by:
All, I think I may have uncovered a bug in the IsNumeric function, or at least a misunderstanding on functionality. I am writing a Schedule Of Classes Application for our campus and have a...
12
by: sck10 | last post by:
Hello, I am trying to determine if a value is NOT numeric in C#. How do you test for "Not IsNumeric"? protected void fvFunding_ItemInserting_Validate(object sender, FormViewInsertEventArgs...
2
by: James | last post by:
Simple question... If you execute a block of statements that uses the IsNumeric function on a text box that contains no data, will it cause a run time error? Thanks looks like this: If...
17
by: MLH | last post by:
I have tested the following in immed window: ?isnumeric(1) True ?isnumeric(1.) True ?isnumeric(1.2) True ?isnumeric(1.2.2)
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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...

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.