-
May 23rd, 2005, 03:09 PM
#1
How can I put the ; in a string?
How can I put the ; in a string?
-
May 23rd, 2005, 03:16 PM
#2
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
-
May 23rd, 2005, 03:25 PM
#3
Re: How can I put the ; in a string?
Originally Posted by dave18285
How can I put the ; in a string?
-
May 23rd, 2005, 03:38 PM
#4
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 ';'
-
May 23rd, 2005, 04:07 PM
#5
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
-
May 23rd, 2005, 04:11 PM
#6
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.
-
May 23rd, 2005, 04:39 PM
#7
Re: How can I put the ; in a string?
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.
-
May 23rd, 2005, 05:12 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|