follows:String sub = str.substring (start, end) + "";Of course Java 7, substring () creates a new char[] array instead of sharing it.For more information, refer to: JDK6 and JDK7 substring () methods and their differences7. String vs StringBuilder vs StringBufferThe StringBuilder is mutable, so you can modify the internal values after creation.StringBuffer are synchronous and therefore thread-safe, but less efficient.8. How do I double-stitch the sam
In either language, string manipulation is an important foundation, often simple and important. Just as people speak, there is a body (graphical interface), there is a language (print string?). Clearly, the string can explain more things. PHP provides a large number of string
16, and once you exceed it, you need to resize once and increase the GC pressure. It is recommended to specify an initial size based on experience values.StringBuilder sb = new StringBuilder (); for (int i = 0; i
6. Avoid misuse of StringBuilder
string concatenation operations such as STR1+STR2+STR3+STR4 are compiled into String.Concat (STR1,STR2,STR3, STR4), but are more efficient than StringBuilder. String.Concat will determine the l
String in Shell: string is the most commonly used and most useful data type in shell programming (in addition to numbers and strings, no other type is easy to use, haha), strings can be in single quotes, or double quotes, or without quotes. The difference between single and double quotes is similar to PHP. Single quotes:
Any character in a single quotation mark is output as is, and the variable in
This article to you to share some Java operation string of some examples, you need to refer to.
Java string comparison
Where the Java lookup string last appeared
Java deletes one character from a string
Java string substitution
Java
"). " //This is case-sensitive.Echo strnatcasecmp("Hello man", "Hello Man"). " //compares the length of two strings before the large return is 1 otherwise it is -1Echo strncmp("I Love china!", "I Love shanghai!", 6). " //compares the first n characters of a string to a case-sensitiveEcho strlen("He Llo"). " //in PHP, the space of a string is the length of a byte that takes upEcho Chunk_split("Hello Man", 1,
+313. Use of Ljust () and Rjust ()>>> Name' MY NAME '>>> Print (Name.ljust (20, "*"))//Note: is the entire string length, "MY name" is a total of 7, so "*" only 13MY name*************>>> Print (Name.rjust (20, "*"))MY NAME14. Case Conversion of strings>>> Name' MY NAME '>>> print (Name.lower ())//lower is to turn uppercase into lowercaseMy Name>>> print (Name.upper ())//upper is to convert lowercase to uppercaseMY NAME15. Remove the carriage return or
Each language has his own string manipulation method, the shell is the same, the following in an example of the way, a simple introduction of common methods.
1, get string length
Copy Code code as follows:
string=abc12342341//equals two sides without spaces
echo ${#
[Zz]linux string manipulation functionPublished 1 years ago (1) strcat (connecting two strings)
Related functions
bcopy,memccpy,memcpy,strcpy,strncpy
Header file
#include
function definition
Char *strcat (char *dest,const char *src);
Function description
strcat () copies the parameter src string to the end of the string
]; -[Scanner scaninteger:Endminute]; -}];We first construct one from the set of whitespace character sets and the punctuation character set NSMutableCharacterSet . Tells you NSScanner to ignore these characters to greatly reduce the necessary logic to parse these characters. scanCharactersFromSet:The incoming alphabetic character set gets the number of days to start and end (optional) within one week of each item. scanInteger Similarly, the next consecutive integer value is obtained. NSCharact
character, and if you do not add 1, replace all + A Print('Druid Chenc'. Split ())#by default, the characters are separated by a space, resulting in a list the Print('Druid Chenc'. Split ('D'))#use D as delimiter + Print('Druid Chenc'. Split ('C'))#with C as the delimiter - Print('1+2+3'. Split ('+'))#with + as delimiter $ Print('1+2\n+3+4'. Splitlines ())#delimited by line break $ - Print('Druid Chen'. Zfill (50))#left with 0 padding - theName1 ='My name is {name},age {age}' - Print(Name1.f
: Display string as Strikethroughdocument.write (Str.strike ());8:split, dividing a string into an arrayConsole.log (Str.split (""));["Hello", "World"]9 Slice (star,end), extracting a string fragmentIncludes the string Stringobject all characters from start (including start) to end (not including end). Star is allowed
(' a ')3. Connect (with join () to concatenate list, tuple,dict to string) 4. Segmentation(spilt () splits the string into list)5. Convert letter case (capitalized), all uppercase letters, all letters lowercase, print a string with style, ... To begin with; End, string substitutionStr.capitalize () #首字母大写Str.upper ()
String manipulation cannot be modified1Say ="Hello, world,66."2 Print(Say.capitalize ())#output Hello, world,66 first letter capitalization3 4 Print(Say.casefold ())#output Hello, world,66 uppercase all lowercase5 6 Print(Say.center (30,"-"))#output-------Hello, world,66-------returns the center of the original string and fills the new
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.