Method of extracting a string after a character in a string using the SSCANF function

Source: Internet
Author: User

1, Example 1:

#include <stdio.h>
#include <stdlib.h>
Main ()
{
Char s[]= "ABC 123 N:XYZ";
Char s2[80];
SSCANF (S, "%*[^:]:%s", S2);
printf ("%s", S2);
}

2, Example 2: Remove the number after =

Format

"Verno=dp_b002_rel_v10", "interval=0", "pwd=000000", "sos_num1=15084781942", "sos_num2=15084781942", "sos_num3= 15084781942 "," sos_num4=15084781942 "," listen_num= "," firewall=1 "," alm=0:0:0;0:0:0;0:0:0;0:0:0;0:0:0;0:0:0;0:0:0 ; 0:0:0; "," PROF=0;7:4:6;0:0:0;0:0:0;7:4:6;

Parsing method:

Verno

SSCANF (list.at (0). Tolocal8bit (). Data (), "%*[^=]=%s", &syncdeviceinfo.verno[0]);

Interval
SSCANF (list.at (1). Tolocal8bit (). Data (), "%*[^=]=%d", &syncdeviceinfo.ninterval);

Pwd
SSCANF (list.at (2). Tolocal8bit (). Data (), "%*[^=]=%d", &syncdeviceinfo.pwd);

Sos_num1
SSCANF (list.at (3). Tolocal8bit (). Data (), "%*[^=]=%s", &syncdeviceinfo.sos_num1[0]);

Method of extracting a string after a character in a string using the SSCANF function

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.