string Basic Operations Gallery
All the string operations supported by the C language standard library are in String.h, and this file is under/usr/include/. Specifically, this file also contains access to the array. The included functions are divided into the following categories: replication, connection, comparison, lookup, and so on.
Table of Contents 1 replication 2 Connections 3 Comparison 4 find 5 other functions 6 strtok function 1 copy
void
The date and time comparison functions in php. This article introduces three commonly used date and time comparison functions, one is for the whole date, the other is for the time comparison only, and the last is for the professional comparison time difference to seconds. The date comparison document introduces three commonly used date and time comparison formats. one is for the whole date, the other is for the time comparison only, and the last is for the professional comparison time difference
I. Problem Description
Given a file, read the strings of each row in the file in sequence (strings are separated by spaces ).
For example, the test.txt file contains the following content:
First second third forth (first line)
Th sixth seventh (second top)
... (Other rows)
The read content is: first second third forth second th sixth seventh
Ii. Problem Solving steps
(1) first read all lines of the file
(2) then read each string in sequence for each line
(3) Finally, the read strings are stor
Compared with explode (), the strtok () function can control the pace. Cut strings as needed. Its advantages are:
1. Multiple separators can be defined at a time. When a function is executed, it is cut by a single separator rather than the entire separator, while explode is cut by the entire separator string. Therefore, explode can be cut in Chinese, while strtok won't. it will be garbled.
2. when using whi
, strstr, strtok
Header file # include
Define the function char * strchr (const char * s, int c );
Function Description strchr () is used to find the first c Address in the parameter s string, and then return the address of the character.
", strcat (a, B ));
}
Execute before strcat (): string (1)
After strcat (): string (1) string (2)
Strchr (find the first occurrence of the specified character in the string)
Related functions: Index, memchr, RINEX, strbrk, strsep, strspn, strstr, strtok
Header file # include
Define the function char * strchr (const char * s, int C );
Function Description strchr () is used to find the first c Address in the parameter S string, and then return the ad
the sum of the number of characters of any character in the Str start Match GroupSTRCSPN is the sum of the number of characters that are different from any character in the group, with the meaning of complement.Look directly at the code to better understand:#include string.h>char* str ="123123,helloWorld";p rintf ( "%d\n", (int) strspn (str,"123,")) ;p rintf ("%d\n", (int) strcspn (str,""));Output results
7
12
Strspn finds the sum of the preceding all 123 and, 7, and STRCSPN
The Strtok () function can control the tempo relative to explode (). Cut strings as needed. Its advantages are:
1, you can define multiple separators at once. When a function is executed, it is cut by a single delimiter rather than by the entire separator, while the explode is cut by the entire separator string. Therefore, explode can be cut in Chinese, and strtok is not, will be garbled.
2, in the use whil
For example, the following code:
$str4="php-class,mysql-class,div-css,0,dreamweaver";$s=strtok($str4,',');while($s!==false){ echo $s.""; $s=strtok(',');}
while ($s ===true) {} Why can't it be displayed?True where to use it ~ ~Beginners Please care O (∩_∩) o~Happy New Year ~
My own understanding is:! ==false will satisfy 1. The value is not equal to 2. The type does not equal, when the
strtok () this parameter is used to set character strings are separated into segments. The STR parameter points to the string to be split, and the delimiters parameter is the split string. When strtok () when the delimiters Delimiter is found in the STR string, the Delimiter is changed to '\ 0. In the first call, strtok () must be given the STR string parameter
multithreaded environment, because there was no concept of multithreading at all. To later multi-threaded in the program more and more popular, the C + + Runtime library in the multi-threaded environment to eat a lot of pain. For example:
(1) errno: In the C standard library, most error codes are assigned to a global variable named errno before the function returns. When multithreading is concurrent, it is possible that the value of the errno of a thread is overwritten by the B thread before it
it is very interesting to say that I think the C language is quite profound. But today, I only know that there is a strtok function. I tried it and suddenly felt how much repetitive work I had done before. Every time you need to parse the configuration file, and each time you need to split the string, you actually split the string by yourself, which is both tiring and error-prone. I will continue to learn more comprehensively! Here we reference A Piec
In python, if the Unix timestamp of the current time is required, I particularly like this:
import timetimestr = time.time()timestamp = int(timestr.split('.')[0])
Here, I like the split function very much. It is available in Java, C #, and python. It is very convenient and you don't have to worry about stepping on mines, but in C/CPP, it will be gone, this is a pity.
If you want to process a string type "192.168.1.254" and want to separate each field, what should we do? The c Standard Library
Char *strtok (char *s, const char *delim);Decomposes a string into a set of strings. S is the string to be decomposed, Delim is the delimiter string.A segmented string starting from the beginning of S. Null is returned when there is no split string.Note: When the Strtok function is called for the first time, the function ignores the spacing delimiter and returns the first character found in the Strtoken str
PHP string functions are widely used in PHP website development. for example, PHP string functions are used to segment, intercept, match, and replace strings. PHP string functions are widely used in PHP website development. for example, PHP string functions are used to segment, intercept, match, and replace strings. PHP string functions are essential for beginners of PHP. This article describes how to process PHP string functions and how to start PHP string functions.
Common PHP string segment
string.Strtok Introduction:function Prototypes:char *strtok (char *s, const char *delim);Function: decomposes A string into a set of strings. S is the string to be decomposed, Delim is the delimiter string.Description: Strtok () is used to split a string into fragments. The parameter S points to the string to be split, the parameter Delim is the split string, and when
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.