• 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. Custom IC SKILL
  3. string evaluation in a long text

Stats

  • Locked Locked
  • Replies 4
  • Subscribers 144
  • Views 13849
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

string evaluation in a long text

DavidLou
DavidLou over 6 years ago

hello experts,

wondering if someone can help me out while I'm scratching my hair off. say I have a long text string like

   "blabla{a+b}{c}tada{d}..."

I want to replace the contents within {} (and remove {} as well) by evaluated values (if not evaluatable then replace by "?").

{} pair could be anywhere.

how can I use some skill code to do that?

thanks a lot,

David

  • Cancel
  • VPrasad
    VPrasad over 6 years ago

    You can use rexCompile and rexReplace to meet your requirement.

    For Example :

                  we have a= "blabla{a+b}{c}tada{d}" then

                 rexCompile( "{[a-zA-Z0-9\\+]*}" )   => t

                 rexReplace( a "(*)" 0) => "blabla(*)(*)tada(*)"

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • DavidLou
    DavidLou over 6 years ago in reply to VPrasad

    thanks VPrasad,

    I could be not clear first hand. I'm looking to evaluate the expression within { } and replace them by the result, so not purely replace by fixed pattern. i.e., if a=1 and b=2, then I should replace {a+b} by 3. 

    is that possible?

    thanks,

    David

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • tweeksii
    tweeksii over 6 years ago in reply to DavidLou

    You bet!

    (defun CCSevalBracedExpressionInLongString (longString)
      (let ((pat (pcreCompile "{(.*)}" (pcreGenCompileOptBits ?ungreedy t))))
        (while (pcreExecute pat longString)
          (let ((value (errset (evalstring (pcreSubstitute "\\1")))))
            (setq longString (pcreReplace pat longString (if value (printself (car value)) "?") 1))))
        longString))
    
    (let ((a 1)
          (b 2)
          (c "hello")
          (d 'unbound))
      (CCSevalBracedExpressionInLongString "blabla{a+b}{c}tada{d}"))
    => "blabla3\"hello\"tada?"    
    

    Thanks for a fun one. Smile

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • DavidLou
    DavidLou over 6 years ago in reply to tweeksii

    OMG~~~~~~      YOU MADE IT!

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

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