Solved

Convert System::String to char or integer

Posted on 2007-11-15
6
1,574 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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 …

739 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