Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3991770
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:39:21+00:00 2026-05-20T06:39:21+00:00

I am trying to write a function to transform a string literal in Delphi/pascal

  • 0

I am trying to write a function to transform a string literal in Delphi/pascal to the C equivalent. A string literal in Delphi matches the regex ("#"([0-9]{1,5}|"$"[0-9a-fA-F]{1,6})|"'"([^']|'')*"'")+ so that the string

"This is a test with a tab\ta breakline\nand apostrophe '"

will be written in Pascal as

'This is a test with a tab'#9'a breakline'#$A'and apostrophe '''

I managed to strip the apostrophes, but I am having trouble managing the special characters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:39:21+00:00Added an answer on May 20, 2026 at 6:39 am

    Simply use replaceApp() function that can be found at: http://www.cppreference.com/wiki/string/basic_string/replace

    Then code can look as:

    string s1 = "This is a test with a tab\\ta breakline\\nand apostrophe '";
    string s2 = s1;
    s2 = replaceAll(s2, "'", "''");
    s2 = replaceAll(s2, "\\t", "'$7'");
    s2 = replaceAll(s2, "\\n", "'$10'");
    cout << "'" << s2 << "'";
    

    Of course changes ‘\t’ -> ‘$7’ can be saved in some structure that you can use in loop instead of replacing each item in separate lines.

    Edit:

    Second solution (example taken from comment) with using map:

    typedef map <string, string> MapType;
    string s3 = "'This is a test with a tab'#9'a breakline'#$A'and apostrophe '''";
    string s5 = s3;
    MapType replace_map;
    replace_map["'#9'"] = "\\t";
    replace_map["'#$A'"] = "\\n";
    replace_map["''"] = "'";
    MapType::const_iterator end = replace_map.end();
    for (MapType::const_iterator it = replace_map.begin(); it != end; ++it)
        s5 = replaceAll(s5, it->first, it->second);
    cout << "s5 = '" << s5 << "'" << endl;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a function that formats every (string) member/variable in an object,
I'm trying to write a function that is able to determine whether a string
I'm trying to write a regex function that will identify and replace a single
I am trying to write a function that will pull the name of a
I am trying to write a function in C++ that solves for X using
I am trying to write a JavaScript function that will return its first argument(function)
I'm trying to write a custom function that will let me retrieve a cell
I'm trying to write a function for a database class that is basically just
I'm trying to write a function in Python that finds the first number in
I am trying to write a function that will check if an object exists:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.