• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Allegro X Scripting - Skill
  3. RE to remove ,

Stats

  • State Suggested Answer
  • Replies 4
  • Answers 1
  • Subscribers 19
  • Views 5981
  • Members are here 0
More Content

RE to remove ,

skillnewbie1
skillnewbie1 over 3 years ago

Hi given a string of 

inPutString = "signal_A{2,4,6,8:10},signal_B,signal_C[10,12:14,16]_E"

is it possible to remove the 2 commas between the 3 signals?

e.g outPutList => ("signal_A{2,4,6,8:10}" "signal_B" "signal_C[10,12:14,16]_E")

  • Cancel
  • Sign in to reply
Parents
  • mstaub
    0 mstaub over 3 years ago

    Some parts of this are a hack, but it works. You might want to explore regular expressions for this as well.

    Text version of the code:

    axlCmdRegister("parsenetstring" 'ParseNetString)

    procedure(ParseNetString( )
    let(((b_validIndex t)
    (s_inPutString "")
    (l_output list())
    (l_temp list())
    (s_curChar "")
    (b_indexFound nil)
    )

    s_inPutString = "signal_A{2,4,6,8:10},signal_B,signal_C[10,12:14,16]_E"

    for(i 1 strlen(s_inPutString)
    b_indexFound = nil
    s_curChar = buildString(list(getchar(s_inPutString i)))

    ;Ignore any commas inside brackets
    if(s_curChar == "{" || s_curChar == "[" then
    b_validIndex = nil
    )

    ;Character is outside of brackets, so it could be a valid comma
    if(s_curChar == "}" || s_curChar == "]" then
    b_validIndex = t
    )

    ;The current character could be a valid comma
    if(b_validIndex then
    ;Valid comma found. Store the
    if(s_curChar == "," then
    b_indexFound = t
    l_output = cons(buildString(reverse(l_temp) "") l_output)
    l_temp = list()
    )
    )

    ;Couldn't find an easy way to remove a portion of a string by a known index so we are
    ; just creating a list of chars which we will build a new string from when a valid
    ; comma is found
    if(!b_indexFound then
    l_temp = cons(s_curChar l_temp)
    )

    ;We are at the end of the string, so add the final value to the list
    if(i==strlen(s_inPutString) then
    l_output = cons(buildString(reverse(l_temp) "") l_output)
    )
    i++
    )

    l_output = reverse(l_output)

    println(l_output)

    )
    )

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • mstaub
    0 mstaub over 3 years ago

    Some parts of this are a hack, but it works. You might want to explore regular expressions for this as well.

    Text version of the code:

    axlCmdRegister("parsenetstring" 'ParseNetString)

    procedure(ParseNetString( )
    let(((b_validIndex t)
    (s_inPutString "")
    (l_output list())
    (l_temp list())
    (s_curChar "")
    (b_indexFound nil)
    )

    s_inPutString = "signal_A{2,4,6,8:10},signal_B,signal_C[10,12:14,16]_E"

    for(i 1 strlen(s_inPutString)
    b_indexFound = nil
    s_curChar = buildString(list(getchar(s_inPutString i)))

    ;Ignore any commas inside brackets
    if(s_curChar == "{" || s_curChar == "[" then
    b_validIndex = nil
    )

    ;Character is outside of brackets, so it could be a valid comma
    if(s_curChar == "}" || s_curChar == "]" then
    b_validIndex = t
    )

    ;The current character could be a valid comma
    if(b_validIndex then
    ;Valid comma found. Store the
    if(s_curChar == "," then
    b_indexFound = t
    l_output = cons(buildString(reverse(l_temp) "") l_output)
    l_temp = list()
    )
    )

    ;Couldn't find an easy way to remove a portion of a string by a known index so we are
    ; just creating a list of chars which we will build a new string from when a valid
    ; comma is found
    if(!b_indexFound then
    l_temp = cons(s_curChar l_temp)
    )

    ;We are at the end of the string, so add the final value to the list
    if(i==strlen(s_inPutString) then
    l_output = cons(buildString(reverse(l_temp) "") l_output)
    )
    i++
    )

    l_output = reverse(l_output)

    println(l_output)

    )
    )

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
  • skillnewbie1
    0 skillnewbie1 over 3 years ago in reply to mstaub

    Hi mstaub, it works and looks good, thx.

    yes, using rex functions can be an alternate option,

    and just to share a workaround  i can think so far:

    1. Use rexCompile and rexExecute to take out (first one Only) the substring of { } and [ ]

    2. Use rexReplace all the " , " from 1 with a string of (non meta) characters that can never be found in a signal name. (say,  "___") 

    3. Use rexReplace (first One Only) to put 2 back into the initial string.

    4. Use while loop for 1-3, and the rexExecute in 1 as a loop checker. 

    5. after 4, parseString with " , " and replace each "___" with " ,  "

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • luanvn81
    0 luanvn81 over 3 years ago in reply to skillnewbie1

    Hi !

    Another way to do that. Try below code.

    (defun test ()
    inPutString = "signal_A{2,4,6,8:10},signal_B,signal_C[10,12:14,16]_E"
    out_str = nil
    foreach(item reverse(parseString(inPutString "signal"))
    item_len = strlen(item)
    if(nindex(item ",") == item_len then
    tmp_str = strcat("signal" subs_tring(item 1 item_len-1))
    else
    tmp_str = strcat("signal" item)
    );end if
    out_str = cons(tmp_str out_str)
    );end foreach
    printf("OUT: %L\n", out_str)
    );end defun

    Note: please remove underline on command sub_string to run code. I can't post without underline on that command.

    Luan.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mstaub
    0 mstaub over 3 years ago in reply to luanvn81

    I had looked into using 'parseString(inPutString "signal")' as well but you making the assumption that 'signal' will always be the prefix. Which could be the case, and if so that would work. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Cadence Guidelines

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information