Good tutorials for String class?

  • Thread starter Thread starter Nathan Young
  • Start date Start date
N

Nathan Young

Hello all,

I am a newbie to C++ (but have been writing C for a while).

I am trying to write a simple TCP/IP program in C++, and am really
struggling with string manipluation. I would appreciate any pointers
to good web tutorials on the String class and manipulating strings.

For example. I have a integer variable 'count' which I would like to
transmit on the TCP stream. I have the stream up and running, and can
transmit static messages using the following code:

String* tempbuf = new String(S"Test data");
Byte myWriteBuffer[] =Text::Encoding::ASCII->GetBytes(tempbuf);
stream->Write(myWriteBuffer, 0, myWriteBuffer->Length);

How would I capture the value of count into the tempbuf string?

In C, I would do something like this...
sprintf(&tempbuf,"Test data, count value: %d",count);
....But I can't figure out the equivalent function with the String
class.

Thanks,
Nathan
 
Nathan said:
Hello all,

I am a newbie to C++ (but have been writing C for a while).

I am trying to write a simple TCP/IP program in C++, and am really
struggling with string manipluation. I would appreciate any pointers
to good web tutorials on the String class and manipulating strings.

For example. I have a integer variable 'count' which I would like to
transmit on the TCP stream. I have the stream up and running, and can
transmit static messages using the following code:

String* tempbuf = new String(S"Test data");
Byte myWriteBuffer[] =Text::Encoding::ASCII->GetBytes(tempbuf);
stream->Write(myWriteBuffer, 0, myWriteBuffer->Length);

How would I capture the value of count into the tempbuf string?

In C, I would do something like this...
sprintf(&tempbuf,"Test data, count value: %d",count);
...But I can't figure out the equivalent function with the String

You can't really write into a String - they're immutable. You can, however,
create a new string instance with the data you desire using String::Format.

String* tempbuf = String::Format(S"Test data, count value:
{0}",__box(count));

HTH

-cd
 
Nathan said:
Hello all,

I am a newbie to C++ (but have been writing C for a while).

I am trying to write a simple TCP/IP program in C++, and am really
struggling with string manipluation. I would appreciate any pointers
to good web tutorials on the String class and manipulating strings.

For example. I have a integer variable 'count' which I would like to
transmit on the TCP stream. I have the stream up and running, and can
transmit static messages using the following code:

String* tempbuf = new String(S"Test data");
Byte myWriteBuffer[] =Text::Encoding::ASCII->GetBytes(tempbuf);
stream->Write(myWriteBuffer, 0, myWriteBuffer->Length);

How would I capture the value of count into the tempbuf string?

In C, I would do something like this...
sprintf(&tempbuf,"Test data, count value: %d",count);
...But I can't figure out the equivalent function with the String

You can't really write into a String - they're immutable. You can, however,
create a new string instance with the data you desire using String::Format.

String* tempbuf = String::Format(S"Test data, count value:
{0}",__box(count));


Thanks!
-Nathan
 
Back
Top