| Subject |
Re: manipulating a string |
| From |
Charlie <tm@tc.com> |
| Date |
Mon, 21 Mar 2022 17:33:39 -0400 |
| Newsgroups |
dbase.getting-started |
Hi Mervyn.... Thanks very much. I got this though... Error: OLE Dispatch Exception.
It is referring to line 14 which is cNew = a.item(0).submatches.item(0)
All fields have a length of 10 but they have an actual length that varies between 6 and 10. Most are less than 10. I am not sure if that is the reason for the error.
To further complicate I have a directory full of images which are named the same as each sku + .jpg. Those names have to be changed at the same time as the sku so possibly a loop would work better to do both at the same time?
Mervyn Bick Wrote:
> On 2022/03/20 16:22, Charlie wrote:
> > Hi... I need to change some of our in house sku numbers for certain categories in our inventory. I am thinking I would do something with the substring but not sure if there is a better way.
> >
> > Actually the skus are characters with a liength of 10 or less. There are two different lengths for different categories. They always start and end with letters, but in the middle of the string is the mfg part no.
> >
> > I want to change skus with 4 digits in the middle and add a zero in front so that they all are usable in a new project.
> >
> > So LI2456EX would become LI02456EX.
> >
> > Any suggestions on the best way to do this?
> >
> > Thanks!
>
> It can be done using dBASE functions but using a regular expression will
> do the job a lot faster.
>
> A little example is attached. It will add 0 to the front of 4 digits
> between any number of character at the beginning of the sku and any
> number of characters at the end of the sku. If there are 5 digits no
> change will be made.
>
> There shouldn't be a problem but make sure you have a backup of the
> table safely tucked away before you run the program.
>
> Mervyn
> use yourtablename
> replace all yourfieldname with update_sku(yourfieldname)
> use
>
> function update_sku(cString)
> if type('oRegExp') = 'U'
> oRegExp = new OleAutoClient("VBScript.RegExp")
> oRegExp.global := true
> oRegExp.ignoreCase := true
> oRegExp.Pattern := "(\D+)(\d+)(\D+)"
> endif
> a = oRegExp.execute( cString )
> cNew = a.item(0).submatches.item(0)
> cNew+= iif(a.item(0).submatches.item(1).length = 4,'0','')
> cNew+= a.item(0).submatches.item(1)
> cNew+= a.item(0).submatches.item(2)
> return cNew
|
|