Getting Started with dart-basic types and regular

Source: Internet
Author: User
Tags greatest common divisor iterable

The underlying data type and regular numbers and Boolean values

The numeric type is the same as the Boolean type as in other languages

Partial properties
    intFigurea =- the;//Figurea is a negative number    Print(figurea.isnegative);//Figurea is limited    Print(Figurea.isfinite);//Figurea whether positive infinity or negative infinity    Print(Figurea.isinfinite); Double Figureb =64.742;//return Figureb symbol,-1.0: value is less than 0, +1.0: value is greater than 0, -0.0/0.0/nan: value is itself    Print(Figureb. Sign);//Returns the type of the Figureb runtime    Print(Figureb.runtimetype);//Return hash code for FIGUREB    Print(Figureb.hashcode);intFigurec = -;//Figurec is an odd number    Print(figurec.isodd);//Figurec is an even number    Print(Figurec.iseven);//Returns the FIGUREC storage bit    Print(Figurec.bitlength);
Common methods
    intFigurea =- the;//Returns the absolute value of the Figurea    Print(Figurea.ABS());//Returns a string of Figurea    Print(Figurea.tostring ()); Double Figureb =64.742;//Returns the integer value of Figureb    Print(Figureb.toint ());//Returns the double value of Figureb    Print(Figureb.todouble ());//Returns a double value greater than Figureb    Print(Figureb.ceiltodouble ());//Returns a double value less than Figureb    Print(Figureb.floortodouble ());//Returns the double value of Figureb rounding    Print(Figureb.roundtodouble ());//Return Figureb A string that retains several decimals    Print(Figureb.tostringasfixed (2));//Return Figureb A string that retains the exact result after several decimals    Print(Figureb.tostringasprecision (3));intFigurec = to;//Figurec vs other integers, 0: Same, 1: greater Than,-1: Less than    Print(Figurec.compareto ( -));//Figurec to control the integer in the specified interval    Print(Figurec.Clamp( -, -));//returns FIGUREC converted to the specified cardinality (binary) string    Print(Figurec.toradixstring ( -));intfigured = A;//Returns the greatest common divisor of figured with other integers    Print(FIGURED.GCD ( -));//Returns the Intercept remainder of FIGUREDG and other integers    Print(Figured.remainder ( -));//Returns a string with a power value of figured several times    Print(Figured.tostringasexponential (2));
string constants and variable string constants

String is immutable, and once defined, it cannot be changed.

"XiaoMing say : \n""""Keep on going ...never give up ...never say die ...""";print(name + say);
Partial properties
    str"Hello world!";    // 返回字符串的UTF-16代码单元列表    print(str.codeUnits);    // 返回根据代码单元生成的哈希码    print(str.hashCode);    // 字符串是否为空    print(str.isEmpty);    // 字符串是否不为空    print(str.isNotEmpty);    // 字符串的长度    print(str.length);    // 返回字符串Unicode代码的可迭代对象    print(str.runes);    // 返回对象运行时的类型    print(str.runtimeType);
Common methods

Returns the string representation of an object

str"Hello world!";print(str.toString());

Intercept string

String‘Dartis fun‘;String newStr = str.substring(04);print(newStr);

Inserting a string in a string

"XiaoMing";print("My name is ${name}");

Unicode encoding of the output string

str"Dart";print(str.codeUnitAt(0));print(str.codeUnits);

Remove space before and after string

str"\tDart is fun\n";print(str.trimLeft());print(str.trimRight());print(str.trim());

Case Conversion of strings

str"ABCdef";print(str.toLowerCase());print(str.toUpperCase());

Splitting a string

"Hello world!";print(strA.split(" ""abba";print(strB.split(new RegExp(r"b*")));

Whether to include other strings

‘Dart strings‘;print(str.contains(‘D‘));print(str.contains(new RegExp(r‘[A-Z]‘)));print(str.contains(‘D‘0));print(str.contains(new RegExp(r‘[A-Z]‘0));

To complement a placeholder before and after a string

str"86";print(str.padLeft(4‘0‘));print(str.padRight(4‘0‘));

Gets the location where the specified character appears

‘Dartisans‘;print(str.indexOf(‘art‘));print(str.indexOf(new RegExp(r‘[A-Z][a-z]‘)));print(str.lastIndexOf(‘a‘));print(str.lastIndexOf(new RegExp(r‘a(r|n)‘)));

Replace all matching characters in a string

"resume";print(str.replaceAll(new RegExp(r‘e‘‘é‘));
String variables

StringBuffer is modifiable and can be modified after definition

StringBuffer xiaomingSaid = new StringBuffer();xiaomingSaid.write("All the world‘s a stage ... ");xiaomingSaid.write("And all the men and women merely players ...");print(xiaomingSaid);
Partial properties
    new StringBuffer();    strBuf.write("Sow nothing, reap nothing.");    // 返回字符串缓冲区的哈希码    print(strBuf.hashCode);    // 字符串缓冲区是否为空    print(strBuf.isEmpty);    // 字符串缓冲区是否不为空    print(strBuf.isNotEmpty);    // 返回字符串缓冲区累积内容的长度    print(strBuf.length);    // 返回对象运行时的类型    print(runtimeType);
Common methods
    new StringBuffer();    // 添加字符串到字符串缓冲区内    strBuf.write("Do one thing at a time, and do well.");    // 返回字符串缓冲区的所有内容    print(strBuf.toString());    // 清除字符串缓冲区    strBuf.clear();
Regular Expression Partial properties
    exp = new RegExp(r"(\w+)");    // 返回正则表达式的哈希码    print(exp.hashCode);    // 正则表达式是否区分大小写    print(exp.isCaseSensitive);    // 正则表达式是否匹配多行    print(exp.isMultiLine);    // 返回源正则表达式字符串    print(exp.pattern);    // 返回对象运行时的类型    print(exp.runtimeType);
Common methods
RegexpExp= new RegExp (r"(\w+)");//Returns an iterative object for a regular expression match    Print(Exp. Allmatches ("ABC def GHI"));//Search and return the first occurrence, none returns null    Print(Exp. Firstmatch (""));//Regular expression finds a match    Print(Exp. Hasmatch ("as"));//Match regular expression starting with the first few characters    Print(Exp. Matchasprefix ("AB CD",3));//Returns the first matching string of a regular expression    Print(Exp. Stringmatch ("ABC de"));//Returns a string representation of a regular expression    Print(Exp. toString ());
Practical cases

Verifies the regular value of a ZIP code, returns whether a matching Boolean

RegExp postalcode = new RegExp(r‘(\d{6})‘);print(postalcode.hasMatch("518000"));

Verify the regular phone number to iterable< match > return all matches

RegExp mobile = new RegExp(r"(0|86|17951)?(13[0-9]|15[0-35-9]|17[0678]|18[0-9]|14[57])[0-9]{8}");Iterable<Match> mobiles = mobile.allMatches("13812345678 12345678901 17012345678");forin mobiles) {    String match = m.group(0);    print(match);}

Verifies the regular URL URL, or returns null if the match returns a match with match

RegExp url = new RegExp(r"^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+");print(url.firstMatch("http://www.google.com"));

Verify the regular of the ID number and return the first matching string

RegExp identity = new RegExp(r"\d{17}[\d|x]|\d{15}");print(identity.stringMatch("My id number is 35082419931023527x"));

Getting Started with dart-basic types and regular

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.