CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2005
    Posts
    25

    How can I put the ; in a string?

    How can I put the ; in a string?

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    Re: How can I put the ; in a string?

    Code:
    std::string myStr = "This is my string";
    myStr.insert(2, ';');
    This inserts a ';' in the second position (in place of the 'i' in "This"). The CString class has a similar function (called, "Insert").

    Viggy

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: How can I put the ; in a string?

    Quote Originally Posted by dave18285
    How can I put the ; in a string?
    Code:
    CString str = ";";
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    May 2005
    Posts
    25

    Re: How can I put the ; in a string?

    Code:
    temptext.Replace(_T("&"), _T('&'));
    why do I get
    ObitText.cpp(187) : error C2143: syntax error : missing ')' before ';'

  5. #5
    Join Date
    Feb 2002
    Posts
    4,640

    Re: How can I put the ; in a string?

    The ';' is not a special character in strings (like '\' is). So, that's not your problem. I think the problem might be the single quotes around the second parameter (the "_T('&')"). Whatever the _T macro expands to, it's not expecting a single character? I don't use UNICODE, so I tend to not use these macros.

    Viggy

  6. #6
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: How can I put the ; in a string?

    Code:
     temptext.Replace(_T("&"), _T("&"));
    is correct.
    Last edited by Siddhartha; May 23rd, 2005 at 04:17 PM.

  7. #7
    Join Date
    May 2005
    Location
    United States
    Posts
    526

    Re: How can I put the ; in a string?

    Quote Originally Posted by MrViggy
    Whatever the _T macro expands to, it's not expecting a single character? I don't use UNICODE, so I tend to not use these macros.
    Just for future reference, _T prepends an L to a string literal if _UNICODE is defined, to indicate that the string should be interpreted as Unicode, and does nothing if _UNICODE is not defined. So assuming he's not working in Unicode:

    temptext.Replace(_T("&"), _T('&'));

    is equivalent to:

    temptext.Replace("&", '&');

    So the problem is as Siddhartha pointed out; he was trying to use a character where a string was expected.

  8. #8
    Join Date
    May 2005
    Posts
    25

    Re: How can I put the ; in a string?

    yea, changing from single to double quotes worked. thanks for the help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured