Solved

Convert System::String to char or integer

Posted on 2007-11-15
6
1,573 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
  • 3
  • 2
6 Comments
 
LVL 45

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 45

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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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 125 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
A short article about a problem I had getting the GPS LocationListener working.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

828 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