I want to parse a string and rename it.
e.g. I would like to check for a cell name, and if there is an hyphen(-) in a cell name, I would like to convert it to an underscore(_).
so if a cell name is 'create-gds' I want to convert it to 'create_gds'. Any help would be appreciated.
Here is one way:
s="create-gds"when(rexMatchp("-" s) rexCompile("-") s=rexReplace(s "_" 0))
In IC61, you can do:
; only need to compile the pattern oncehyphen=pcreCompile("-") ; then any time you need to do the replace, can reference the pattern object in var hyphencellName="create-gds"newCell=pcreReplace(hyphen cellName "_" 0)
In IC61 and IC5141 you can use the less powerful rex functions (but the compiled pattern will get overwritten if it is used elsewhere since it only has a single compiled pattern at once):
rexCompile("-")cellName="create-gds"newCell=rexReplace(cellName "_" 0)
The pcre functions have a much richer pattern matching syntax - see the PCRE web site for more details.
In reply to dmay:
My feeling is that for char substitution the most safe,simple, fast way is to use buildString() and parseString() procedures.
myCellName = "create-gds-2"myCellName = buildString(parseString(myCellName "-") "_")"create_gds_2"
In reply to marcelpreda:
Actually I'd go for a regular expression approach. If you have multiple occurrences of the delimiter, or leading or trailing delimiters, it won't work properly. For example:
myCellName="-hello-world--test" myCellName = buildString(parseString(myCellName "-") "_") "hello_world_test"
In reply to Andrew Beckett:
This type of replacement happens where ? Is it in the Schematic viewer or in the Created Netlist or in the Layout Editor ?
In reply to RFStuff:
I don't understand your question. This post is about doing pattern replacement in SKILL, so it's nothing to do with a particular application.