function | The string manipulation function in string PHP3.0 is much more important for the following:
(1) echo,print,printf,sprintf
is used for output strings. If a variable name is substituted in the string, it is replaced with its value. The latter two functions are similar to C's with the same name function.
= ' Howareyoumyboy 'SELECT CHARINDEX (' is ', @str)Output: 4This function cannot be used with text and image data types.(2), PATINDEX ()Returns the beginning of the occurrence of a specified substring in a string.PATINDEX (Unlike the CHARINDEX function, wildcard characters can be used in substrings of the PATINDEX function, and this function can be used with char, VARCHAR, and text data types.ExDECLARE @str VARCHAR (200)SET @str = ' Howareyoumyboy 'SELECT PATINDEX ('%you% ', @str)Output: 7EX2:S
-a-test-test-string"Specific usage, such as the following table:
An expression
meaning
Example
${org_str/Sub_str/replace_str}
Replace the first matching $sub_str with the value of $REPLACE_STR
${org_str/test/TEST} #得到This-is-a-TEST-test-string
${org_str//Sub_str/replace_str}
Replace all matching $sub_str with the value of $REPLACE_
= = c) {p = str; Each occurrence of the position is recorded, p will always change}str++;} if (*str = = ') return (char *) P;else return NULL;}Third, STRRSTR ()We all know that there is strstr () in the library function, which is looking for the self-string, but like above, if we want to implement a function that returns the last occurrence of a substring in a specified string. So, since Strstr () is
string subscript, can not find the errorName.upper ()#Turn all letters into uppercaseName.lower ()#Turn all letters into lowercasefile_name='A.xls'Print(File_name.endswith ('. xls'))#determines whether a string ends in XLSF='{Name} welcome'Print(F.format (name='Suki'))#string Formattingd={'name':'Suki'," Age":' -'}Print(D.format_map (d))#
1. String substitution functionStr_replace () replaces a string or array element, is case-sensitive, and the 4th parameter is optional for statistical The number of replacements.
Str_ireplace () case- insensitive STRTR () replaces any character in a string2. String comparison functionstrcmp () compares strings if equal returns 0 if the
, two pound sign (# #) means to intercept the longest match from the left (the ABBC,DEF,GHI,ABC string is removed here)Echo${str#"A*c"} # Output ABBC,DEF,GHI,ABCJKL because STR does not have"A*c"Sub-stringEcho${str##"A*c"} # Output ABBC,DEF,GHI,ABCJKL similarlyEcho${str#*a*c*the shortest string of *a*c* is ABBC, so the output is truncated, def,ghi,abcjklEcho${str##*a*c*} # Empty, * The longest
()Function: Truncate the strings specified on both sides of the string, then the default is to remove the white space character (including ' \ n ', ' \ R ', ' \ t ', ')" Hello World">>> str1.strip ()'Hello World '19.string.split (str = ", Num=string.count (str))Function: Slice string with the str divider, and if NUM has a specified value, only the NUM substring is splitThe str--delimiter, which defa
This article mainly introduces the summary of the 5 C # string manipulation methods to share, this article explained that the string to be converted to List by separator, the string to follow, split into data, get array list comma-delimited string, get
I, and the plus characters can be filled as: result = Name.center (20, ' * ') Count counts the number of occurrences of a string as name = ' Adsfasdfasdf ' Name.count (' DS ') can calculate the total number of DS in name and can also specify the starting position Name.count (' DS ', 0, 3) encode Encode the string for example: Name = ' Li Fangyuan ' result = Name.encode (' GBK ') Str.endswith () see if the
one, the string is ""ReplaceAll ("", ""):Equals (): Determines whether two strings are equal (S1,equals (S2));Split (","): String splittoUpperCase (): Convert uppercaseFlow Control Branch Loop statementIf.....elseIf.....else If....elseSwitch (value 0) {//value 0 is what type, the following value is what typeCase value 1:Execute the statement;BreakDefaultExecute the statement;Break}while (condition) {}do{}w
String: It is a finite sequence of 0 or more characters in a finite character set//a special linear table int Indexz (string s,string t,int pos) {//t is a non-empty string, if there is a substring equal to T after the first POS character in the main string S, Returns the pos
specified variable to the specified content. printf"%d\n", i); intb; SSCANF (S8,"%d+%d=", a, b); printf ("%d,%d\n", A, b); Const Char*p = STRCHR (S7,'=');//Find charactersprintf"%s\n", p); P= Strstr (S7,"b");//Find Stringprintf"%s\n", p); strcpy (S7,"abc_123_ee_xx"); P=strtok (S7,"_");//Replace _ to 0//printf ("%s,%p,%p\n", p, p, S7); //P=strtok (NULL, "_");//How do you know which is the right operation???? //printf ("%s,%p,%p\n", p, p, S7); //P=strtok (NULL, "_");//How do you know which is the
string is found, the function returns the address of the first matching string, or NULL if the searched string is not found .
NBSP;
extern char * strstr ( char NBSP; *str1, const NBSP; Char NBSP; *str2);
str1: target being searched for stringexpression to search.str2: to find an object thestring expressio
The examples in this article describe the common problems with PHP string manipulation. Share to everyone for your reference, specific as follows:
Remember the first time to learn PHP to listen to the words of a cow x is: All procedures are strings, the so-called programming just let the data like water in the various code page flow between the flow. I do find that the data format is a difficult problem in
Topic Information1084. Broken Keyboard (a)Time limit of MSMemory Limit 65536 KBCode length limit 16000 BOn a broken keyboard, some of the keys is worn out. If you are type some sentences, the characters corresponding to those keys won't appear on screen.Now given a string of you is supposed to type, and the string is actually type out, please list those keys which Is for sure worn out.Input Specification:Ea
The fourth function seems to use the CType bar oneself seems to be very troublesome later to use again,#include #include void Direct_output (char **ptr){ int i;For (i=0;iputs (ptr[i]);}void Asc_output (char **ptr){int i,j;For (i=0;i{For (j=0;j {if (strcmp (ptr[j],ptr[j+1]) >0) {Char *temp;Temp=ptr[j];ptr[j]=ptr[j+1];ptr[j+1]=temp;} }}direct_output (PTR);}void Strlen_output (char **ptr){int i,j;For (i=0;i{For (j=0;j {if (strlen (Ptr[j]) >strlen (ptr[j+1])) {Char *temp;Temp=ptr[j];ptr[j]=ptr[j+1];
One, capitalize the first letter of the string to return a new string1.1 Simple notation, capitalize the first letter of a wordString.prototype.firstUpperCase =function){Returnthis[0].touppercase () +This.slice (1); }1.2 Capitalize all words in a string, not first letter lowercaseString.prototype.firstUpperCase =function){ReturnThis.replace (/\b (\w) (\w*)/g,function ($0, $, $) {//\b represents delimiters S
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.