How do I change a byte variable so that I can add it's character value to
the end of a variable of type string, such that:

String^ s = "1234";
byte b;
b= 53;

s = s + b;

thus s = "12345".

I wasn't able to use a cast.

s = s + (char)b;

did not work.

Daniel

Re: how to cast byte to char by David

David
Wed Jul 16 21:22:06 CDT 2008

Daniel wrote:
> How do I change a byte variable so that I can add it's character value to
> the end of a variable of type string, such that:
>
> String^ s = "1234";
> byte b;
> b= 53;
>
> s = s + b;
>
> thus s = "12345".
>
> I wasn't able to use a cast.
>
> s = s + (char)b;
>
> did not work.

Daniel:

1. It would be good if you were to consider whether you are using standard C++
or C++/CLI (two *different* languages), and post accordingly.

2. It would also be good if you described what "did not work". What did you
expect, and what happened? Did the code fail to compile? Or link? Or run? Or to
give the result you expected?

--
David Wilkinson
Visual C++ MVP

Re: how to cast byte to char by Jim

Jim
Wed Jul 16 22:06:14 CDT 2008

"Daniel" <newsonly@cableone.net> wrote in message
news:OCwug$55IHA.4468@TK2MSFTNGP02.phx.gbl...
> How do I change a byte variable so that I can add it's character value to
> the end of a variable of type string, such that:
>
> String^ s = "1234";

c++ has no type String. Without a definition, type, struct or class that is
a syntax error. ^ is a syntax error. That is not C++

> byte b;

c++ has no type byte. Without a typedef or structure or class definition
that is a syntax error. That is not C++

> b= 53;
>
> s = s + b;
>
> thus s = "12345".
>
> I wasn't able to use a cast.
>
> s = s + (char)b;
>
> did not work.

Of course it didn't work, that's not legal C++ code. If you mean to ask
about some other language, please post in a newsgroup about that other
language.

Thank you.
--
Jim Langston



Re: how to cast byte to char by Daniel

Daniel
Wed Jul 16 22:27:19 CDT 2008

In the example that I gave, s=s+b resulted in s. The b did not get
concatenated. As for standard C++ or C++/CLI, I can't tell the difference.
I'm not that well versed in the technology to be able to tell you.

Daniel

"David Wilkinson" <no-reply@effisols.com> wrote in message
news:eL7loP75IHA.192@TK2MSFTNGP06.phx.gbl...
> Daniel wrote:
>> How do I change a byte variable so that I can add it's character value to
>> the end of a variable of type string, such that:
>>
>> String^ s = "1234";
>> byte b;
>> b= 53;
>>
>> s = s + b;
>>
>> thus s = "12345".
>>
>> I wasn't able to use a cast.
>>
>> s = s + (char)b;
>>
>> did not work.
>
> Daniel:
>
> 1. It would be good if you were to consider whether you are using standard
> C++ or C++/CLI (two *different* languages), and post accordingly.
>
> 2. It would also be good if you described what "did not work". What did
> you expect, and what happened? Did the code fail to compile? Or link? Or
> run? Or to give the result you expected?
>
> --
> David Wilkinson
> Visual C++ MVP



Re: how to cast byte to char by David

David
Thu Jul 17 06:42:10 CDT 2008

Daniel wrote:
> In the example that I gave, s=s+b resulted in s. The b did not get
> concatenated. As for standard C++ or C++/CLI, I can't tell the difference.
> I'm not that well versed in the technology to be able to tell you.

Daniel:

If you do not know whether you are using standard C++ or C++/CLI, and why, you
need to stop what you are doing and find out.

From the limited information that you present here, I would say there there is
a very high probability that you should be learning C#.

--
David Wilkinson
Visual C++ MVP

Re: how to cast byte to char by Ben

Ben
Thu Jul 17 08:52:20 CDT 2008

Jim Langston wrote:
> "Daniel" <newsonly@cableone.net> wrote in message
> news:OCwug$55IHA.4468@TK2MSFTNGP02.phx.gbl...
>> How do I change a byte variable so that I can add it's character
>> value to the end of a variable of type string, such that:
>>
>> String^ s = "1234";
>
> c++ has no type String. Without a definition, type, struct or class
> that is a syntax error. ^ is a syntax error. That is not C++
>
>> byte b;
>
> c++ has no type byte. Without a typedef or structure or class
> definition that is a syntax error. That is not C++
>
>> b= 53;
>>
>> s = s + b;
>>
>> thus s = "12345".
>>
>> I wasn't able to use a cast.
>>
>> s = s + (char)b;
>>
>> did not work.
>
> Of course it didn't work, that's not legal C++ code. If you mean to
> ask about some other language, please post in a newsgroup about that
> other language.

He did. microsoft.public.dotnet.languages.vc is the correct ng for C++/CLI.

>
> Thank you.



Re: how to cast byte to char by Ben

Ben
Thu Jul 17 08:52:54 CDT 2008

Daniel wrote:
> How do I change a byte variable so that I can add it's character
> value to the end of a variable of type string, such that:
>
> String^ s = "1234";
> byte b;
> b= 53;
>
> s = s + b;
>
> thus s = "12345".
>
> I wasn't able to use a cast.
>
> s = s + (char)b;

Try wchar_t instead, or System::Char.

>
> did not work.
>
> Daniel



Re: how to cast byte to char by David

David
Thu Jul 17 09:11:57 CDT 2008

Ben Voigt [C++ MVP] wrote:
> He did. microsoft.public.dotnet.languages.vc is the correct ng for C++/CLI.

Ben:

Yes, but microsoft.public.vc.language is not.

In fact the OP appears unaware that C++ and C++/CLI are different languages. But
the solution is to learn the difference, not to cross-post.

--
David Wilkinson
Visual C++ MVP

Re: how to cast byte to char by David

David
Thu Jul 17 11:24:21 CDT 2008

Daniel wrote:
> In the example that I gave, s=s+b resulted in s. The b did not get
> concatenated. As for standard C++ or C++/CLI, I can't tell the difference.
> I'm not that well versed in the technology to be able to tell you.

Daniel:

To answer your question, if I do

String^ s = L"1234";
byte b = 53;
s = s + b; // or s +(char)b

then I get "123453" (isn't this what happened for you?).

But if I do

String^ s = L"1234";
byte b = 53;
s = s + (wchar_t)b;

then I get "12345", which I think is what you wanted.

This is because System::String contains wide characters (wchar_t), not 8-bit
characters (char), and the + operator is overloaded for wchar_t.

Note that, although you can initialize System::String with "" string (8-bit
string), you should always use L"" (wide string) in C++/CLI.

C++/CLI is not an easy language, and you might well be better off learning C#.
C++/CLI is essentially standard C++ and C# combined together in one (often
confusing) language.

--
David Wilkinson
Visual C++ MVP

Re: how to cast byte to char by Daniel

Daniel
Thu Jul 17 11:59:14 CDT 2008

That explanation on C++/CLI was helpful. I found example code that used the
^ notation after the type name in the MSDN help that came with Visual
Studio. I had never seen that notation before. I thought it was part of
.NET and not necessarily C#. Thanks for the explanation.

Daniel

"David Wilkinson" <no-reply@effisols.com> wrote in message
news:e2pWRmC6IHA.616@TK2MSFTNGP02.phx.gbl...
> Daniel wrote:
>> In the example that I gave, s=s+b resulted in s. The b did not get
>> concatenated. As for standard C++ or C++/CLI, I can't tell the
>> difference. I'm not that well versed in the technology to be able to tell
>> you.
>
> Daniel:
>
> To answer your question, if I do
>
> String^ s = L"1234";
> byte b = 53;
> s = s + b; // or s +(char)b
>
> then I get "123453" (isn't this what happened for you?).
>
> But if I do
>
> String^ s = L"1234";
> byte b = 53;
> s = s + (wchar_t)b;
>
> then I get "12345", which I think is what you wanted.
>
> This is because System::String contains wide characters (wchar_t), not
> 8-bit characters (char), and the + operator is overloaded for wchar_t.
>
> Note that, although you can initialize System::String with "" string
> (8-bit string), you should always use L"" (wide string) in C++/CLI.
>
> C++/CLI is not an easy language, and you might well be better off learning
> C#. C++/CLI is essentially standard C++ and C# combined together in one
> (often confusing) language.
>
> --
> David Wilkinson
> Visual C++ MVP



Re: how to cast byte to char by David

David
Thu Jul 17 12:27:09 CDT 2008

Daniel wrote:
> That explanation on C++/CLI was helpful. I found example code that used the
> ^ notation after the type name in the MSDN help that came with Visual
> Studio. I had never seen that notation before. I thought it was part of
> .NET and not necessarily C#. Thanks for the explanation.

Daniel:

I would really advise you to get a firm grip on what all these things mean. The
^ notation is not part of .NET (or of C#); it is a feature of the C++/CLI
language, which (unlike standard C++) can target the .NET framework. Not the
same thing.

There are three *different* languages:

C# (managed)
C++ (native/unmanaged)
C++/CLI (mixed)

Both C# and C++/CLI can target the .NET framework. However, Microsoft is no
longer promoting C++/CLI as a first class .NET language for GUI applications.
They only promote it for interfacing between managed and native code.

All new GUI development should be done in C# (or VB.NET). This is why you should
think carefully before investing a lot of time in C++/CLI.

--
David Wilkinson
Visual C++ MVP

Re: how to cast byte to char by Daniel

Daniel
Thu Jul 17 17:21:53 CDT 2008

ok. Thanks for the advice. I'll have to consider that carefully.

Daniel

"David Wilkinson" <no-reply@effisols.com> wrote in message
news:%238NQXJD6IHA.3684@TK2MSFTNGP05.phx.gbl...
> Daniel wrote:
>> That explanation on C++/CLI was helpful. I found example code that used
>> the ^ notation after the type name in the MSDN help that came with Visual
>> Studio. I had never seen that notation before. I thought it was part of
>> .NET and not necessarily C#. Thanks for the explanation.
>
> Daniel:
>
> I would really advise you to get a firm grip on what all these things
> mean. The ^ notation is not part of .NET (or of C#); it is a feature of
> the C++/CLI language, which (unlike standard C++) can target the .NET
> framework. Not the same thing.
>
> There are three *different* languages:
>
> C# (managed)
> C++ (native/unmanaged)
> C++/CLI (mixed)
>
> Both C# and C++/CLI can target the .NET framework. However, Microsoft is
> no longer promoting C++/CLI as a first class .NET language for GUI
> applications. They only promote it for interfacing between managed and
> native code.
>
> All new GUI development should be done in C# (or VB.NET). This is why you
> should think carefully before investing a lot of time in C++/CLI.
>
> --
> David Wilkinson
> Visual C++ MVP



Re: how to cast byte to char by Joe

Joe
Fri Jul 18 03:27:00 CDT 2008

On Jul 17, 7:58=A0am, "Daniel" <newso...@cableone.net> wrote:
> How do I change a byte variable so that I can add it's character value to
> the end of a variable of type string, such that:
>
> String^ s =3D "1234";
> byte b;
> b=3D 53;
>
> s =3D s + b;
>
> thus s =3D "12345".
>
> I wasn't able to use a cast.
>
> s =3D s + (char)b;
>
> did not work.
>
> Daniel

I think you programming in C++/CLI, so u can try this:
String^ s =3D L"1234";
Byte b =3D 53;

s +=3D gcnew String((wchar_t)b, 1);