• 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. How to interpret a single backslash from an input file?

Stats

  • Replies 1
  • Subscribers 145
  • Views 33
  • Members are here 0

How to interpret a single backslash from an input file?

MM202511045434
MM202511045434 15 hours ago

I am trying to read a net name from an input file which looks like this: "DUT.XPLL_ANA_TOP\|CLKN\\<2\\>"

I am using gets() function to read net name, since I want to read the file one line at a time. I am entering the net name in the input file as: DUT.XPLL_ANA_TOP\|CLKN\<2\>

But gets() interprets it as "DUT.XPLL_ANA_TOP\\|CLKN\\<2\\>", i.e., it automatically converts the single backslash to double backslash. The last 2 double backslashes in the net name are fine, since I want them to be there, but I do not want \| to be converted into \\|. 

I also used pcre* function in order to replace \| with \\|.

cs=pcreCompile("[\\|]")
mystr2=pcreReplace(cs mystring "\|" 1)

But that's not working, that interprets mystr2 still as "DUT.XPLL_ANA_TOP\\|CLKN\\<2\\>".

So, how can I interpret \| in a net name correctly?

  • Cancel
  • Sign in to reply
Parents
  • Andrew Beckett
    Andrew Beckett 4 hours ago

    You’re misinterpreting what the characters actually are. When you look at the value of a string variable, it shows it using the print representation, which is valid syntax for representing the string as input. Since \ is an escape character within strings, an actual \ has to be escaped to show it in the print representation and hence it would appear as \\.

    If you are expecting it to be read as in the first line, you should enter it exactly as you described in the first place - ie with \| first and then \\<2\\> later. The print representation shows that as \\| and \\\\<2\\\\> at the end. This is correct.

    Assuming that you have the string read by gets in a variable called netName, try just doing:

    printf(“%s\n” netName)

    (apologies if the quotes are wrong - I’m typing this in a bus in Germany!). It will print correctly.

    To convince you, try using parseString(netName “”) - this will split into individual characters. You will see some “\\” amongst those because it has to escape the backslash. It’s still a a single character though - if you do strlen(“\\”) it will return 1.

    Hope that helps!

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett 4 hours ago

    You’re misinterpreting what the characters actually are. When you look at the value of a string variable, it shows it using the print representation, which is valid syntax for representing the string as input. Since \ is an escape character within strings, an actual \ has to be escaped to show it in the print representation and hence it would appear as \\.

    If you are expecting it to be read as in the first line, you should enter it exactly as you described in the first place - ie with \| first and then \\<2\\> later. The print representation shows that as \\| and \\\\<2\\\\> at the end. This is correct.

    Assuming that you have the string read by gets in a variable called netName, try just doing:

    printf(“%s\n” netName)

    (apologies if the quotes are wrong - I’m typing this in a bus in Germany!). It will print correctly.

    To convince you, try using parseString(netName “”) - this will split into individual characters. You will see some “\\” amongst those because it has to escape the backslash. It’s still a a single character though - if you do strlen(“\\”) it will return 1.

    Hope that helps!

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data

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