字串(string)1.宣告
var mystring = new string("every good boy does fine.");
var mystring = "every good boy does fine.";
2.字串連線
var mystring = "every " + "good boy " + "does fine.";
var mystring = "every "; mystring += "good boy does fine.";
3.擷取字串
//擷取第 6 位開始的字元
var mystring = "every good boy does fine.";
var section = mystring.substring(6); //結果: "good boy does fine."
//擷取第 0 位開始至第 10 位為止的字元
var mystring = "every good boy does fine.";
var section = mystring.substring(0,10); //結果: "every good"
//擷取從第 11 位到倒數第 6 位為止的字元
var mystring = "every good boy does fine.";
var section = mystring.slice(11,-6); //結果: "boy does"
//從第 6 位開始擷取長度為 4 的字元
var mystring = "every good boy does fine.";
var section = mystring.substr(6,4); //結果: "good"
4.轉換大小寫
var mystring = "hello";
var lcstring = mystring.tolowercase(); //結果: "hello"
var ucstring = mystring.touppercase(); //結果: "hello"
5.字串比較
var astring = "hello!";
var bstring = new string("hello!");
if( astring == "hello!" ) //結果: true
if( astring == bstring ) //結果: true
if( astring === bstring ) //結果: false (兩個物件不同,儘管它們的值相同)
6.檢索字串
var mystring = "hello everybody.";
// 如果檢索不到會返回-1,檢索到的話返回在該串中的起始位置
if( mystring.indexof("every") > -1 ) //結果: true
7.查詢替換字串
var mystring = "i is your father.";
var result = mystring.replace("is","am"); //結果: "i am your father."
8.特殊字元:
\b : 後退符 \t : 水平製表符
\n : 換行符 \v : 垂直製表符
\f : 分頁符 \r : 回車符
\" : 雙引號 \' : 單引號
\\ : 反斜桿
9.將字元轉換成unicode編碼
var mystring = "hello";
var code = mystring.charcodeat(3); //返回"l"的unicode編碼(整型)
var char = string.fromcharcode(66); //返回unicode為66的字元
10.將字串轉換成url編碼
var mystring = "hello all";
var code = encodeuri(mystring); //結果: "hello%20all"
var str = decodeuri(code); //結果: "hello all"
//相應的還有: encodeuricomponent() decodeuricomponent()
常用字串函式
memset 原型 extern void memset void buffer,int c,int count 用法 include 功能 把buffer所指記憶體區域的前count個位元組設定成字元c。說明 返回指向buffer的指標。舉例 memset.c include include ma...
常用字串函式
獲取檔案目錄 dirname c test web home.php 將字串填充到指定長度 str pad str,10,str pad both 重複指定字串 str repeat 4 按照指定長度將字串分割到陣列中 str split str,4 字串反轉 strrev str 大小寫轉換 st...
常用字串函式
strlen string 得到字串長度 strpos string,search offset 在指定字串中查詢目標字串第一次出現的位置 stripos string,search offset 忽略大小寫的去查詢 strrpos string,search offset 在指定字串中查詢目標字串...