One, string manipulation//String to array string mystring= "This is a string" char[] mychars=mystring. ToCharArray ();//foreach loop processing char array foreach (char mychar in mystring) {Console.WriteLine (MyChar);} MyString. Length//Get the number of elements two, turn t
values registered by Codecs.register_error. This section covers the codecs module, which is not a specific understandingS.decode ([encoding,[errors]])26, the string test, the judgment function, this kind of function is not in the string module, these functions return is the BOOL valueCopy the code code as follows: S.startswith (Prefix[,start[,end]])#是否以prefix开头S.endswith (Suffix[,start[,end])#以suffix结尾S.is
PHP Learning Path III (string manipulation)
";? >
";//returns-1 because the ASCII value of the lowercase letter is greater than the value of the uppercase grandmother Echo strcasecmp (" ABCD "," ABCD ").";//Return 0?>
"; Echo strstr ($parent, $needle).""; $text =" This is a test ", $needle =" is "; Echo strlen ($text).""; Echo Substr_count ($text, $needle)."";//return result is 2echo substr_count ($tex
The function of string manipulation in PHP3.0 is much more, and it is important to have the following:
(1) echo,print,printf,sprintf
Used for the output string. If there is a variable name in the string, it is replaced with its value. The latter two functions are similar to C's with the same name function.
(2) STRC
string.Reset S N: Changes the nth string to S.Print N: Prints the nth string of output.Printall: Prints out all strings.Over: End operation.Where n,x,l can be composed of find and rfind operation expressions, S,S1,S2 can be composed of copy and add operation expressions.InputFirst behavior an integer n (n between 1-20)Next n behaves n strings, strings do not contain spaces and operation commands, and so on
use Type output value, return Print (' idiot '. Join (' You are ', ', he is ', '. ]) Output: You are a fool, he is a fool. , type, return 11,maketrans and Translatep = Str.maketrans (' abcdef ', ' 123456 ') # ' abcdef ' corresponds to ' 123456 ' one by onePrint (' Lao Cui '. Translate (p)) #替换12,rplace (replace)Print ('Lao cui haha'. Replace ('a','a' ) # Replace all of the small a in the string with a, the default full substitution, and the fo
Package Day01;import Org.junit.test;public class TestString {/** * Test constant POOL * * */@Testpublic void Testconstantpool () {String str1 = "Hello";//string str2 = "Hello";//two objects are compared using = =, and a return value of TRUE indicates that the two object references refer to the same memory area System.out.println (str1 = = str2); String str3 = new
leftWline="hello \ n World"Print("==splitlines==")Print(Wline.splitlines ())#splitlines the row to return a list containing the rows as elementsPrint("==isalpha==")Print(Wline.isalpha ())#returns false because there are spaces, escape characters#Isalpha Determines whether all characters in a string are letters, the letter returns True, and the other returns falseNum="12233"Print("==isdigit==")Print(Num.isdigit ())#IsDigit Determines whether all chara
end of the string.Echo.Echo-----------------------------------------------Set strinterception1=%str1:~0,4%Set strinterception2=%str1:~1,4%Set strinterception3=%str1:~5%Echo strinterception1=%strinterception1%Echo strinterception2=%strinterception2%Echo strinterception3=%strinterception3%:: Similar to strlen, gets the length of the string.:: Implementation method: Using Goto and tags to form a looping structure, the
Take a look at the following code:Program Testrecord;{$APPTYPE CONSOLE}UsesSysutils,Math;TypeTrecorda = Recordname:string;EndProcedure Runtestrecord;VarR1, R2:trecorda;BeginR1. Name: = Stringofchar (' A ', Randomrange (64, 256) * 1024);Move (R1, R2, SizeOf (R1));EndVarI:integer;BeginTryFor I: = 0 to 100000-1 doRuntestrecord;ExceptOn E:exception doWriteln (E.classname, ': ', e.message);EndEnd.Because of the string type in the structure, the red part is
String manipulation#!/usr/bin/env python#-*-Coding:utf-8-*-Name =' Wang 'user =' WANG 'print (dir)#dir see which members of the class can use thePrint (type (name)) #显示使用的哪个类result = name. __contains__ (' W ') #inPrint (Result)result = name. capitalize () #首字母大写Print (Result)result = user. casefold () #大写字母变小写Print (Result)result= name. Center ("*") #长度是20. Fill with * number, center keywordPrint (Result)le
When looking at some open source code, we often see some string manipulation functions, which are available under the Linux platform, but MS is not provided on the Windows platform. Therefore, the software must be implemented by itself. Common Library functions are:Obtains a copy of the current character, freeing the memory externally. Char *strdup (const char *src) { int len; Char
Concat () – combines two or more characters of text to return a new string.IndexOf () – returns the index at the first occurrence of a substring in a string. If there is no match, returns-1.CharAt () – returns the character at the specified position.LastIndexOf () – Returns the index of the last occurrence of a substring in a string, or 1 if there is no match.Match () – checks whether a
Concat () – combines two or more characters of text to return a new string.IndexOf () – returns the index at the first occurrence of a substring in a string. If there is no match, returns-1.CharAt () – returns the character at the specified position.LastIndexOf () – Returns the index of the last occurrence of a substring in a string, or 1 if there is no match.Match () – checks whether a
negative argument to the length of the string---> // This is : substr (7,5), which intercepts 5 characters from position 7 // "Rld" // convert the second argument to 0 // That is : substr (3,0), which is to intercept 0 strings from position 3, returns an empty // ""3. IE compatibilityIf the substr () method passes a negative value, there is a problem, and the original string is returned. IE9 fixed this is
of a string: StringBuilder.The class encapsulates a mutable string, in other words, when we need to change the contents of the string, we do not create a new object, but rather modify it on the basis of the original object. This reduces the overhead of memory.2.2. Using Append to implement appendStringBuilder Append (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.