473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to assign a 'char *' to a text property of a control

Hi, I'm new at Visual C++ and I can't figure out how to change the text
property of a label. I'm using a char[] variable that I'd like to assign to
the label. Perhaps I should use a System::String^ instead? But when I try
that, I get an error that I can't use a System::String^ as a global or static
variable. What I want to be able to do is the change say the third character
of the text in the text property of the label control from, say, 'k' to 'm'.
Maybe there's a very simple way to do this.
Aug 28 '07 #1
2 2410

"Steven" <St****@discussions.microsoft.comwrote in message
news:DD**********************************@microsof t.com...
Hi, I'm new at Visual C++ and I can't figure out how to change the text
property of a label. I'm using a char[] variable that I'd like to assign
to
the label. Perhaps I should use a System::String^ instead? But when I try
that, I get an error that I can't use a System::String^ as a global or
static
variable. What I want to be able to do is the change say the third
character
of the text in the text property of the label control from, say, 'k' to
'm'.
Maybe there's a very simple way to do this.
There's a String constructor that accepts a C++ char (.NET SByte), so:

char* the_text = "Some ordinary string here."
label1->Text = gcnew String(the_text);

However, that's going to do an ASCII->Unicode conversion. You may be
happier using .NET Char (C++ wchar_t) arrays. To do that you have to write
your string literals like L"string" and character literals like L'm'.

Getting to individual (Unicode) characters of .NET Strings is easy:

interior_ptr<wchar_tunistr = PtrToStringChars(label->Text);

To do the simple replacement you mentioned, you might do:

array<wchar_t>^ s = label->Text->ToCharArray();
if (s[2] == L'k') s[2] == L'm';
label->Text = new String(s);
Aug 29 '07 #2
You don't say what environment you are using? Is this managed or unmanaged
code? If managed, look at Ben Voigt's reply. If not, you are dealing with
window handles. Now, are you doing raw C++, ATL, WTL, or MFC? If the former,
investigate SetWindowText(hwnd, "here is a string").

/steveA

Steven wrote:
Hi, I'm new at Visual C++ and I can't figure out how to change the text
property of a label. I'm using a char[] variable that I'd like to assign to
the label. Perhaps I should use a System::String^ instead? But when I try
that, I get an error that I can't use a System::String^ as a global or static
variable. What I want to be able to do is the change say the third character
of the text in the text property of the label control from, say, 'k' to 'm'.
Maybe there's a very simple way to do this.
Sep 1 '07 #3

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

Similar topics

4
by: Cengiz Ulku | last post by:
Hi, I've already posted a question similar but will need some precisions and help. I have a rtf file displayed within a RTB control. Above it, I have a text box control with a scroller which...
4
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; ...
12
by: Mark Kurten | last post by:
i have the code below: for starters the value of txtempid = 1 after i go through this routine (i put a break point on the txtname.value line), the value of txtEmpID is 2 (Just like it is...
2
by: Abhishek Srivastava | last post by:
Hello All, I have bound an ArrayList to a repeater control. When the list is displayed, I want the the user to be able to choose one of the items in the list and then continue working. To...
4
by: Leor Amikam | last post by:
I want to use a css element and apply it to all labels on a page with the "asp:label" tag. I defined a CSS class: ..cls1 { font-weight: bold; color: royalblue; font-family: Verdana;
0
by: JJ_377 | last post by:
The following doesn't assign value to the dropdownlist - WHY? ___________________________________________________________________ In a user control (ascx named USACustomer) : Public Property...
6
by: david | last post by:
I try to use "for" loop to retrieve and assign values in web form. The code is in the following. But it can not be compiled. What I want to do is: txtQ1.Text =...
2
by: rachit.goyal | last post by:
Hi All, I am using .net first time.In my windows form VC7 application, on a click of button, I am assigning text of TextBox to STL string varibale. Using this code- private: System::Void...
0
by: =?Utf-8?B?U3RldmVu?= | last post by:
Hi, I'm new at Visual C++ and I can't figure out how to change the text property of a label. I'm using a char variable that I'd like to assign to the label. Perhaps I should use a System::String^...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.