This is the STL implementation of some of the string processing functions and commonly used string processing techniques, experience is basic error, can be used directly, if there is a problem, can be listed accordinglyIncludes: Splitstring to
344. Reverse StringWrite a function that takes a string as input and returns the string reversed.Example:Given s = "Hello", Return "Olleh".Subscribe to see which companies asked this question Public classSolution { Publicstring reversestring (string
Strlen ("string");//Take the length of the string strcmp ("string", "string"); Determines whether two strings are the same, returns 0, differs by 1, and is case-sensitive strcasecmp ("string", "string"); Determine whether two strings are the same,
String handling Issues
ZH (Chinese) en (English) ja (Japanese)
The above string,
If the language is zh, display "Chinese"
If the language is en, "English" is displayed.
If the language is JA, display "Japanese"
How to implement such a function
1. String conversionsS.lower () to lowercaseS.upper () to uppercaseS.swapcase () uppercase to lowercase, lowercase to uppercaseS.capitalize () Capitalize first letterConvert to int type string.atoi (s) or int (s)Convert to float type string.atof (s)
String slices:${var:offset:number}Offset: The number of strings to skipNumber: The string to be fetchedCases:Name= "Obama"${name:1:2}--Displays the result as Ba${name:1}--Displays the result as BamaTake the rightmost few characters of the string:
Now there are a lot of tools on the site to deal with JSON format, but I looked for a day, found that most of the need to write the corresponding object class to deal with, more trouble, such as: Gson,json-lib. Gson,json-lib these parameters, such
1. String merging and linkingPlus sign MergeJoin method Merge2, multiply and sliceLine= ' * ' *30Print (line)>>******************************Slice:Consequence[start_index:end_index:step]Represents the first element, the positive index position
1.eval ()
function: evaluates the string str as a valid expression and returns the result of the calculation.Syntax: eval (source[, globals[, locals]), valueParameters:
Source: The code object returned by a Python expression
1) ASCIIFormat:ascii (character_expression)Function: Returns the ASCII value of the leftmost character of an expression.egSelect ASCII (' abcdef ')GoResult:2) CHAR:Format:char (integer_expression), integer_expression is an integer between
About the processing of strings:1. Take the length of the stringStrlen ();Examples:Show Results:2. String comparison, case-sensitive, same return 0strcmp ();Examples:strings are not equal;Show Results:String equalityShow Results:3. String comparison,
String
Note the difference between single and double quotation marks
Note the escape character \ 's use \\,\ ", \$
Note Using 8-or 16-character notation \xf6
echo "H\xf6me";//need to see if this type of text encoding is supported
--------------------
1. String output function
Echo
Print
No echo high efficiency, not recommended
Die ()
Exit and print the string A, you can also die directly
Printf
formatting strings
sprintf
Returns a formatted string
2. Commonly used string formatting
List several forgotten in the PHP language but very powerful string processing functions, here is not the use of an example, interested friends can test themselves.
(PHP 4 >= 4.0.4, PHP 5)
Function prototype bool Ctype_alnum (string
String processing problem preg_replace (), there is a strange substitution, Daniel solve!
http://.com/item.htm?id=14135039282&ref=http%3A%2F%2Fsearch8.taobao.com%2Fsearch%3Fq%3D%25C4%25DA%25BF%
Tag:for html code htm re ar One, the string output 1, Echo () Direct output 2, print () and echo as direct output, but there will be a return value 0 1 3, printf () formatted output 4, sprintf () returns the formatted string
These features are explained below.
1, intercept the string
Intercepting a string can be said to be one of the most common functions of string processing, one or more characters that can be used to intercept a particular position in a string.
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.