|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
IsNumeric questionI 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 can't you just check for the character "-" and replace it with a "." ?
Show quoteHide quote "Paul" <i**@home.co.uk> schreef in bericht news:oLqdnVkuNJMEtNvYRVnysA@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 > 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 Show quoteHide quote "Joris De Groote" <joris.degro***@skynet.be> wrote in message news:efBagWE$GHA.4888@TK2MSFTNGP04.phx.gbl... > can't you just check for the character "-" and replace it with a "." ? > > > "Paul" <i**@home.co.uk> schreef in bericht > news:oLqdnVkuNJMEtNvYRVnysA@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 > > > > 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: Show quoteHide quote > 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 > If IsNumeric(newname.Substring(1, 3)) Then Replace that with this:> 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 Thanks, Seth Rowe rowe_newsgroups wrote: Show quoteHide quote > 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 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 Show quoteHide quote "rowe_newsgroups" <rowe_em***@yahoo.com> wrote in message news:1162230152.282906.113390@k70g2000cwa.googlegroups.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 > > Sorry again, I posted my second message after you had provided me with the Yeah, sorry about the typo in the first post - I tend to type before I> replacement code. 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: Show quoteHide quote > 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" <rowe_em***@yahoo.com> wrote in message > news:1162230152.282906.113390@k70g2000cwa.googlegroups.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 > > Perfect! Thanks so much
Seth the String Master! Cheers, Paul Show quoteHide quote "rowe_newsgroups" <rowe_em***@yahoo.com> wrote in message news:1162234840.256436.224950@e64g2000cwd.googlegroups.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" <rowe_em***@yahoo.com> wrote in message >> news:1162230152.282906.113390@k70g2000cwa.googlegroups.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 >> > > 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 Show quoteHide quote "rowe_newsgroups" <rowe_em***@yahoo.com> wrote in message news:1162228554.078217.43900@f16g2000cwb.googlegroups.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 > 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: Show quoteHide quote > 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" <rowe_em***@yahoo.com> wrote in message > news:1162228554.078217.43900@f16g2000cwb.googlegroups.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 > > 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 Show quoteHide quote "Paul" <i**@home.co.uk> schreef in bericht news:oLqdnVkuNJMEtNvYRVnysA@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 > 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 Show quoteHide quote > 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 Paul wrote:
> Hi, <snip>> 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. ") 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.
Mixed types in multidimensional arrays
Can't override CultureInfo.ToString More than one method is found with VB but not with C# Access dynamic controls by name? Multiple Component Classes Messages Did Mabry Software Tank! GET SUBNET LOCATION IN VB.NET OT-develing on several machines Sum column of a DataGridVuew |
|||||||||||||||||||||||