472,986 Members | 3,017 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 software developers and data experts.

How to make a CString to 2 lines?

I have a CString with 100 characters. Now i want to make that to 2
lines.

For example,

CString str = "This is just a test to find out how to break a
cstring";

I want this CString in the following format,

CString str1 = This is just a test to find
out how to break a cstring

ie, it should come in 2 lines.

I tried using line break (\n). But that doesn't work.

This was the code that i used.,

CString str = "This is just a test to find out how to break a
cstring";

int i = str.GetLength();

CString str1 = str.Left(i/2);

str1 += '\n';

str1+= str.Right(i/2);

str = str1; // But this is not working. It's not coming in 2 lines.

Is there any other way i can do this?
Dec 9 '07 #1
9 7814
On 2007-12-09 20:32, Donos wrote:
I have a CString with 100 characters. Now i want to make that to 2
lines.
CString is not part of the C++ standard library and thus off-topic in
this group, try asking in a group for Windows programming or MFC. Line-
breaks on Windows is usually represented by two characters, first a
carriage return and then a linefeed (\r\n), you could try using that.

--
Erik Wikström
Dec 9 '07 #2
Erik Wikström <Er***********@telia.comwrote:
On 2007-12-09 20:32, Donos wrote:
I have a CString with 100 characters. Now i want to make that to 2
lines.

CString is not part of the C++ standard library and thus off-topic in
this group, try asking in a group for Windows programming or MFC. Line-
breaks on Windows is usually represented by two characters, first a
carriage return and then a linefeed (\r\n), you could try using that.
As I understand it, the \n "character" is defined as whatever it takes
to break a string into two lines.

Run time libraries may convert between the newline character and some
other character(s) (or lack of characters) during execution (such as
compacting the carriage return/line feed combination into the newline
character or generating the newline character at the end of a logical
record or transforming between various record separators and the
newline character).
(http://www.osdata.com/topic/language/cplus.htm)
Dec 9 '07 #3
Donos <do******@gmail.comwrote:
I have a CString with 100 characters. Now i want to make that to 2
lines.

For example,

CString str = "This is just a test to find out how to break a
cstring";

I want this CString in the following format,

CString str1 = This is just a test to find
out how to break a cstring

ie, it should come in 2 lines.

I tried using line break (\n). But that doesn't work.

This was the code that i used.,

CString str = "This is just a test to find out how to break a
cstring";

int i = str.GetLength();

CString str1 = str.Left(i/2);

str1 += '\n';

str1+= str.Right(i/2);

str = str1; // But this is not working. It's not coming in 2 lines.

Is there any other way i can do this?
What do you mean by "coming in 2 lines"? What does the following print
on the screen?

#include <string>

int main() {
std::string str = "This is just a test to find\nout how to break a
cstring.";
cout << str;
}
Dec 9 '07 #4
On Dec 10, 4:32 am, Donos <dongu...@gmail.comwrote:
I have a CString with 100 characters. Now i want to make that to 2
lines.

For example,

CString str = "This is just a test to find out how to break a
cstring";

I want this CString in the following format,

CString str1 = This is just a test to find
out how to break a cstring

ie, it should come in 2 lines.

I tried using line break (\n). But that doesn't work.

This was the code that i used.,

CString str = "This is just a test to find out how to break a
cstring";

int i = str.GetLength();

CString str1 = str.Left(i/2);

str1 += '\n';

str1+= str.Right(i/2);

str = str1; // But this is not working. It's not coming in 2 lines.

Is there any other way i can do this?
This an offtopic to this group.
Probably you may be needed to give "\r\n" (carriage return and new
line) to make in two lines. You can use the Insert or another useful
interface to insert the desired characters inbetween the string. So
that you can avoid creating temporary objects.

Regards,
Sarath
Dec 10 '07 #5
Daniel T. wrote:
Erik Wikström <Er***********@telia.comwrote:
>On 2007-12-09 20:32, Donos wrote:
I have a CString with 100 characters. Now i want to make that to 2
lines.

CString is not part of the C++ standard library and thus off-topic in
this group, try asking in a group for Windows programming or MFC. Line-
breaks on Windows is usually represented by two characters, first a
carriage return and then a linefeed (\r\n), you could try using that.

As I understand it, the \n "character" is defined as whatever it takes
to break a string into two lines.
Not exactly. It's defined as one signle character. The transformation
happens when doing file I/O in text mode.

Dec 10 '07 #6
On Dec 9, 8:46 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-12-09 20:32, Donos wrote:
I have a CString with 100 characters. Now i want to make
that to 2 lines.
CString is not part of the C++ standard library and thus
off-topic in this group, try asking in a group for Windows
programming or MFC. Line- breaks on Windows is usually
represented by two characters, first a carriage return and
then a linefeed (\r\n), you could try using that.
It wouldn't be C++ if that were the case. In C++, a line is a
sequence of printable characters, terminated by a '\n'
character.

Any other representation of a new line is purely external to the
program, and is mapped in std::filebuf, if the file is opened in
text mode.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Dec 10 '07 #7
On Mon, 10 Dec 2007 05:31:36 -0800, James Kanze wrote:
On Dec 9, 8:46 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
>On 2007-12-09 20:32, Donos wrote:
I have a CString with 100 characters. Now i want to make that to 2
lines.
>CString is not part of the C++ standard library and thus off-topic in
this group, try asking in a group for Windows programming or MFC. Line-
breaks on Windows is usually represented by two characters, first a
carriage return and then a linefeed (\r\n), you could try using that.

It wouldn't be C++ if that were the case. In C++, a line is a sequence
of printable characters, terminated by a '\n' character.

Any other representation of a new line is purely external to the
program, and is mapped in std::filebuf, if the file is opened in text
mode.
It's true if he tries to output his CString to a file, but maybe he tries
to show it on some label or text box.

--
Tadeusz B. Kopec (tk****@NOSPAMPLEASElife.pl)
Horner's Five Thumb Postulate:
Experience varies directly with equipment ruined.
Dec 10 '07 #8
On 2007-12-10 13:59:16 -0500, "Tadeusz B. Kopec"
<tk****@NOSPAMPLEASElife.plsaid:
On Mon, 10 Dec 2007 05:31:36 -0800, James Kanze wrote:
>On Dec 9, 8:46 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
>>On 2007-12-09 20:32, Donos wrote:
>>>I have a CString with 100 characters. Now i want to make that to 2
lines.
>>CString is not part of the C++ standard library and thus off-topic in
this group, try asking in a group for Windows programming or MFC. Line-
breaks on Windows is usually represented by two characters, first a
carriage return and then a linefeed (\r\n), you could try using that.

It wouldn't be C++ if that were the case. In C++, a line is a sequence
of printable characters, terminated by a '\n' character.

Any other representation of a new line is purely external to the
program, and is mapped in std::filebuf, if the file is opened in text
mode.

It's true if he tries to output his CString to a file, but maybe he tries
to show it on some label or text box.
Indeed. But standard C++ has neither a label (as the term is used here)
nor a text box. If some operating system has system calls that don't
handle C/C++ newlines correctly, the right place to discuss how to use
those system calls is a newsgroup that discusses that operating system.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Dec 10 '07 #9
Pete Becker wrote:
On 2007-12-10 13:59:16 -0500, "Tadeusz B. Kopec"
<tk****@NOSPAMPLEASElife.plsaid:
>On Mon, 10 Dec 2007 05:31:36 -0800, James Kanze wrote:
>>On Dec 9, 8:46 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-12-09 20:32, Donos wrote:

I have a CString with 100 characters. Now i want to make that to 2
lines.

CString is not part of the C++ standard library and thus off-topic
in this group, try asking in a group for Windows programming or
MFC. Line- breaks on Windows is usually represented by two
characters, first a carriage return and then a linefeed (\r\n),
you could try using that.

It wouldn't be C++ if that were the case. In C++, a line is a
sequence of printable characters, terminated by a '\n' character.

Any other representation of a new line is purely external to the
program, and is mapped in std::filebuf, if the file is opened in
text mode.

It's true if he tries to output his CString to a file, but maybe he
tries to show it on some label or text box.

Indeed. But standard C++ has neither a label (as the term is used
here) nor a text box. If some operating system has system calls that
don't handle C/C++ newlines correctly, the right place to discuss how
to use those system calls is a newsgroup that discusses that
operating system.
Or just ask the OP how he knows it's not two lines, what he's using to view
them. So OP, how do you know it's not two lines? Have you tried outputing
them to std::cout?

--
Jim Langston
ta*******@rocketmail.com
Dec 10 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Rajesh Garg | last post by:
Why and in what situations is CString not preferred? RVG
6
by: Markus Hämmerli | last post by:
I ' ll tra to convert a Cstring to char* without success. I working in a Unicode enabled environment this is working in Unicode CString source = _T("TestString"); TCHAR *szSource =...
8
by: Oskar | last post by:
Hi. I`m new in cpp and i have a litlle problem. i have a CString from Edit Box (eg."aaa bbb ccc 7327373 d feaf 323 dvjiv 234") and i want to put the data (space separated) into an array.It shuld...
5
by: The Beast | last post by:
I'm trying to create a thread to write to the serial port and I keep getting an odd error cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned long (__stdcall *)(void *)' and...
3
by: nsyforce | last post by:
What is the correct way to convert a const char* to a CString? I'm somewhat of a newbie and have tried several ways. While they all convert ok, I'm using a profiler that shows a memory leak for...
4
by: huguogang | last post by:
Just curious, any one know what the 3 part parameter "class CString filename" would mean. The code: int TestFunc(class CString filename) { fopen(filename, "w"); } Compile using Visaul C++,...
4
by: Susan Rice | last post by:
I'm new to using CString. Why won't the following compile? I'm using Microsoft Visual C++ 6.0 Line 37 which it complains about is the function: 37 CString ConvertFile(char *szFileName) I...
2
by: flyingxu | last post by:
Hi, I run into a cstring related link problem in VC7. My solution has 3 projects, one MFC exe, two MFC extersion DLL. the two MFC extersion DLL export functions which use CString as parameters....
1
by: Tim Kelley | last post by:
I am new to Visual C++ and I am having difficulty parsing a string. We have a database that has a text field that contains multiple lines (seperated by a carriage return and new line characters). ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.