Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Convert System::String to char or integer

Posted on 2007-11-15
6
Medium Priority
?
1,578 Views
Last Modified: 2008-02-01
How do I convert a System::String to a char of a certain length or a long integer?
0
Comment
Question by:sprnova
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 20290002
Hi sprnova,

The easiest is the substring method.

system::String MyString = 'This is a string of chars';

  MyString.SubString (1);    // 'T'

  Mystring.SubString (6,2);   //  'is'



Good Luck,
Kent
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 20290020
Hi sprnova,

Sorry.  My head's been in DB2 all morning.

The offset (start) parameter to SubString() is relative 0, not relative 1.

system::String MyString = 'This is a string of chars';

  MyString.SubString (0);    // 'T'

  Mystring.SubString (5,2);   //  'is'




Good Luck,
Kent
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20290349
>> or a long integer

string s = "124";
long l = Convert.ToInt64(s);

Open in new window

0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 40

Expert Comment

by:evilrix
ID: 20290366
I'll try again but in the right language this time...

System::String ^s = gcnew System::String("124");
long l = Convert::ToInt32(s);

Open in new window

0
 

Author Comment

by:sprnova
ID: 20290486
Sorry.  My head's been in DB2 all morning.

The offset (start) parameter to SubString() is relative 0, not relative 1.

system::String MyString = 'This is a string of chars';

  MyString.SubString (0);    // 'T'

  Mystring.SubString (5,2);   //  'is'

Using substring can I copy the variable into a char of a certain length:

char name[15];

0
 
LVL 40

Accepted Solution

by:
evilrix earned 500 total points
ID: 20291194
Once you have the sub-string you can do with it as you wish...
// Original string is 10 chars in length
System::String ^s1 = gcnew System::String("1234567890");
// New string is 4 chars in length ---> do with it as you wish!
System::String ^s2 = s1->Substring(2,4);

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Simple Linear Regression
Starting up a Project
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question