PHP is often used to process string characters. php's built-in character functions provide very powerful functions that can basically complete most character processing operations, for example, use the str_split function to convert a character into an array, the implode function converts an array into one character, the strpos function searches for another character in one character, and the substr function obtains a certain number of characters in the character. the
Sizeof and strlen are always confused. Let's summarize them today:
Char ch [] = "ABCDE ";Cout Cout
Char character [100] = "ABCDE ";Cout
Cout Char * PCH = "ABCDE ";Cout
Sizeof refers to the actual occupied size (including \ 0)
Strlen indicates the actual character size (excluding \ 0)
The array size is not degraded (as a pointer)
The pointer remains unchanged (generally int type)
If the character
Definitions and usageThe length string returned by the strlen () function.
His role is to calculate the length of the word character, in Chinese a word is 2Grammar
Strlen (String)
Parameter
Description
String
Required. Specifies the string to check
Let's look at a simple example.
Output is
12
I. STR
(pattern,A string that finds the latest (most recent) value.Pattern: Required String
Example:
{www.linuxea.com:agent.version.str ("beta8")}=1This expression returns true if the current Zabbix agent version contains BETA8 (assuming the current version is 1.0beta8).
{www.zabbix.com:jmx["catalina:type=protocolhandler,port=8080", Comprssin].str (off)}=1Indicates that the device www.zabbix.com gets the string off from key
{JMX templates:jmx["Java.lang:type=runtime", Vmname].str (server**)
(char) = 6str3 has been defined as an array with a length of 8, so sizeof (str3) is similar to 8str4 and str2, '0' '1 '... '9' and '\ 0' are 11 characters in total, so SS occupies 8 space. For pointers, the sizeof operator returns the space occupied by the pointer, which is generally 4 bytes; for an array, sizeof returns the total space occupied by all elements in the array. Char * and char [] are easy to confuse and must be distinguished. In addition, char * = "AAA" is not recommended and shou
Recently with the students to Exchange C language library function realization, found that their learning can not be used flexibly, so I opened the fire mode, the first to implement the common library functions.Strlen () function descriptionReturns the length of the specified string, excluding the end character '/0 'Implementing Prototypes:int Mystrlen (const char *STR){int n;while (*str++! = ')n++;return n;}The following function is a test functionvoid Main (){int m;Char a[100];printf ("Please
Method One: The way the pointer is#include #include int My_strlen (const char *STR){char *tmp = str; Save the address of the original pointer with TMPwhile (*STR)//str++ until '/'{str++;}return str-tmp; Subtract two pointers to get the length of a character}int main (){Char *p = "bit";printf ("%d\n", My_strlen (p));System ("pause");return 0;}Method Two: Counter mode#include int My_strlen (const char *ptr){int len = 0;while (*PTR){len++; Reads a string, counter +1ptr++;}return Len;}int main (){Ch
1111111100000000
When the program calculates strlen (P), it stops when it encounters 8 zeros, so it is 255*4 + 3 = 1023.
Why the result is 1020? (PS: My CPU is intel, and Intel's CPU is usually small-end storage) This involves memory storage issues.
As we all know, memory storage is divided into big-end and small-end storage. Big-end storage is what we humans understand. High-end storage is written in front, and its position is written in the ba
1. Implement strlen library functions without local and global variables
The implementation method with variables is:
(1) Regardless of EfficiencySimple implementation
Size_t strlen_a (const char * Str) {size_t length = 0; while (* STR ++) ++ length; return length ;}
It can also be slightly improved as follows:
Size_t strlen_ B (const char * Str) {const char * CP = STR; while (* CP ++); Return (CP-str-1 );}
However, variables cannot be
Pointers Small Knowledge Points:int a = 10;int *p=a;int *q=p; The address of A is saved in Pint *q=p; Assigning the value of p to the Q function is to let Q also point to aStrlen (); To find the length of a stringstrcpy (); Copy stringStrcat (); Connection stringstrcmp (); Comparison of string sizes1typedef unsignedintsize_t2 3size_t My_strlen (Const Char*str)//strlen ()4 {5ASSERT (str!=NULL);6 intlen=0;7 while(*str! =' /') 8 {9len+
Write the first word of a string into another array to write the program as followsThe result is a bit unexpected and re-enter a string, the result is unexpectedly as I have thought that this function is characters stop, but after several input why there is a difference? Tried several different lengths of strings, and found that the first space appeared right after the nineth character, and that it would be wrong to appear before the 9th one! Then I tried the next keyword sizeof () it no matter
This paper analyzes the usage of strlen and Mb_strlen in PHP. Share to everyone for your reference, as follows:
First look at the following code (file encoding UTF8):
Operation Result:
int. INT int 9 int 19
The 2nd parameter, together with the original encoding of the string, calculates the actual word count in the sense of human understanding. (only 1 times in Chinese characters)
I hope this article is helpful to you in PHP programmin
Character Array Function, connected to the strcat replication function strcpy comparison function strcmp length function strlen, strcatstrcmp
Before we learned the data type, there was a char type, which allowed us to put a character inside.
Char variable1 = 'O ';
Char variable2 = 'K ';
# Include
Outputs a diamond image using a two-dimensional array of characters.
# Include
What is the length of this character array?Char talk [10] = {'I', '', 'A', '
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.