Solved

Convert System::String to char or integer

Posted on 2007-11-15
6
1,570 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:Kdo
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:Kdo
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now