| Subject |
Re: manipulating a string |
| From |
Mervyn Bick <invalid@invalid.invalid> |
| Date |
Sun, 20 Mar 2022 18:51:56 +0200 |
| Newsgroups |
dbase.getting-started |
| Attachment(s) |
update_sku.prg |
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
|