C + + string parsing

Source: Internet
Author: User
String parsing, is a string into, multiple strings out.
More broadly speaking is a string into, a data structure variable out.

A broader understanding is the flow of information.


The simplest command to parse a character is scanf. It embodies the important thought.
But the scanf is inflexible and inflexible, and when the actual need is not met,
You need to write your own parsing function, and here's an analysis of the key steps of parsing:

A: Find key characters or strings: (Other Keywords: index, indexof, etc.)
/C/STRCHR, STRSTR,
/C + +/Find, find_first_of, find_last_of
B: Extract string: (Other keywords, left,right, mid, etc.)
/c/strcpy, strncpy
/C + +/substr
C has a split function that can be used to convert a single string to multiple strings,
But you can't return it as an array (be sure to use an array, just a pair of shoes itching suspicion, not concise)
Instead, you use a while loop operation. Process a string at a time.
C: The string is converted to numeric values. (Other keywords: toint tolong toascii, etc.)
/C/atoi, STR2
/c++/has workflow based operations, complete type conversion << >>
This implements the split up and splits the string into different structural variables

Application:
A. Splits the string into arrays, thus turning the input into a different array of parameters (params)
1. Find the flag character or string.
2. Extract String.
3. Storing in array

C + + has a dynamic array (vector), dynamic list (list), eliminating the allocation of maintenance of the array of annoyance.

B. Split key value pairs.
1. Divide the string into 2 strings based on the delimiter,
One for key and one for value.


As for merging strings, it is more broadly a struct for input and a string for output.
It's easier, I call it a get operation, and the front parse can also be called a set operation
/c/sprintf, strcat,strcpy
/c++/+, sstream operation.
C + + String class has a very good string operation code, additions and deletions to check all over, pay attention to its header file code

The above is a broad understanding of get/set.

The analysis of binary data will further involve more technology.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.