Solved

How to split this in C++

Posted on 2016-09-08
4
103 Views
Last Modified: 2016-10-06
Hi Experts. I'm new to C++. I would like to know how can I split this and assign it to variables.
X56345521^Surname/Initials^542153120000000000000000?

Open in new window


I want to extract it like this:

Variable1 = X56345521
Variable2 = Surname
Variable3 = Initials
Variable4 = 542153
Variable5 = 2000000000

I think the best way for Surname and Initials is to get them both as an array then split it up which I think will be a bit easy to get as its has special characters, but already have a code to get it as an array,  now need to assign each data to a correct variable.

The code I have is:
array<String^>^ ParseMyData(String^ data)
 {
     String^ tempData = data->Split(gcnew String('^',1)->ToCharArray())[1];
     return tempData->Split(gcnew String('/',1)->ToCharArray());
 }

Open in new window


Thank you.
0
Comment
Question by:MCSI Developers
  • 2
4 Comments
 
LVL 24

Accepted Solution

by:
chaau earned 250 total points
ID: 41790699
FYI: you can pass multiple delimiters to the Split function:
return data Split(gcnew String("^/")->ToCharArray());

Open in new window

0
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 41790753
What is the rule for splitting on the 2000000000 ?
0
 
LVL 1

Author Comment

by:MCSI Developers
ID: 41792239
Hi, I think it will be better if we ignore the 2000000000 because some devices doesn't support IDC writing so, I've thought of another way around so, extracting 2000000000 is no longer impotent as I will get this with another method of using a database.

The reason is that this data will not always the same in length so that might produce other internal errors. But still need to know on how I can get these:
Variable1 = X56345521
Variable2 = Surname
Variable3 = Initials
Variable4 = 542153

* The rule for getting the first data is that you get all the data on the left hand side before the first ^ sign.
* The rule for getting Surname is that you get the data after the first ^ sign and before the / sign.
* The rule for getting the Initials is that you get the data after the / sign and before the ^ sign.
* The rule for getting the last variable data is that you get the first 6 digits after the last ^ sign or after the second ^ sign

Thank you.
0
 
LVL 54

Assisted Solution

by:Julian Hansen
Julian Hansen earned 250 total points
ID: 41792275
Then chaau seems to have provided the answer. You can call split with multiple separators. This returns an array. You using the indices of the elements you want to access their values.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

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…
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

832 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