• 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. Convert "xxxxxb#b" to "xxxxx<#>"

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 143
  • Views 20606
  • 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

Convert "xxxxxb#b" to "xxxxx<#>"

MorrisDH
MorrisDH over 6 years ago

Where "xxxxx" can be any sub string and "#" can be any number. However "#" would rarely be more than two digits. The two "b" characters that are converted to "<" and ">" are always "b".

An example input string would be "abcdb9b" with the required return string being "abcd<9>".

I have a solution that appears work but it's ugly.

procedure( charReplace(string)
  let( ( inDex m1 m2 m3 mb str1 str2 )
    inDex = length(lindex(parseString(string "") "b" ?all t))
    m1 = pcreCompile( "b[0-9]+b$" )
    m2 = pcreCompile( "b$" )
    m3 = pcreCompile( "b[0-9]+>$" )
    mb = pcreCompile( "b" )
    if(pcreExecute(m1 string) then
      println("match m1")
      str1 = pcreReplace( m2 string ">" 0)
      if(pcreExecute(m3 str1) then
       println("match m3")
       str2 = pcreReplace( mb str1 "<" inDex - 1)
       println(str2)
      ) ; if
    ) ; if
  ) ; let
) ; proc

My main problem was how to replace the last 'b' with '>' and the second to last 'b' with '<'. I worked it out by first creating a new string with the last b (b$) replaced first and then operating on the new string to replace the second to last 'b'.

There must be a better way so I'm open to all comments, advice, suggestions, or questions.

Thanks in advance and cheers to all.

  • Cancel
  • RiadKaced
    RiadKaced over 6 years ago

    Hi MorrisDH,

    What about this ?

    procedure(charReplace(str)

      when(pcreMatchp("(.+)b([0-9]+)b$" str)

        sprintf(nil "%s<%s>" pcreSubstitute("\\1") pcreSubstitute("\\2"))

      )

    )

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • MorrisDH
    MorrisDH over 6 years ago in reply to RiadKaced

    That works.

    I need to read up on pcreSubstitute but that's OK.

    Thanks,

    • 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