Solved

Convert System::String to char or integer

Posted on 2007-11-15
6
1,575 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 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
Stressed Out?

Watch some penguins on the livecam!

 
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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

724 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