字串物件

2021-08-01 06:40:26 字數 1987 閱讀 6075

對一直字串進行操作

var str="life is a foreign language;all men mispronounce it";
測試長度

str.length;
為字串新增樣式

var txt="hello world!"

document.write("big: " + txt.big() + "

")document.write("small: " + txt.small() + "

")document.write("bold: " + txt.bold() + "

")document.write("italic: " + txt.italics() + "

")document.write("blink: " + txt.blink() + " (does not work in ie)

")//在很多瀏覽器中不可用,閃爍

document.write("fixed: " + txt.fixed() + "

")//打字機字型

document.write("strike: " + txt.strike() + "

")//加下劃線

document.write("fontcolor: " + txt.fontcolor("red") + "

")//字型顏色有些改變

document.write("fontsize: " + txt.fontsize(16) + "

")document.write("lowercase: " + txt.tolowercase() + "

")document.write("uppercase: " + txt.touppercase() + "

")document.write("subscript: " + txt.sub() + "

")document.write("superscript: " + txt.sup() + "

")document.write("link: " + txt.link("") + "

")

自認為不太熟的

document.write("fontcolor: " + txt.fontcolor("red") + "

")//字型顏色有些改變

document.write("subscript: " + txt.sub() + "

")//把字串顯示為下標

document.write("superscript: " + txt.sup() + "

")//把字串顯示為上標

document.write("link: " + txt.link("") + "

")

在新增鏈結時 應注意新增的是url

indexof() 方法

如何使用 indexof() 來定位字串中某乙個指定的字元首次出現的位置。

document.write(txt.indexof("life")+"

");document.write(txt.indexof("it") + "

")document.write(txt.indexof("it"));

match() 方法

如何使用 match() 來查詢字串中特定的字元,並且如果找到的話,則返回這個字元。

document.write(txt.match("men")+"

");document.write(txt.match("gilr"));

replace()方法

alert(txt.replace(/men/,"women"));
詳情可見/jsref/jsref_obj_string.asp

字串物件python int 字串 字串物件

最近研究字串物件,稍微總結一下,以後繼續補充 如果我們須要把python的字串物件轉換為數整物件,我們須要用到int方法。比如 ainfo 222 print int ainfo 輸出的結果是222。然後我們檢視下ainfo在現的型別,通過type方法檢視下,發現是 而如果ainfo fefew22...

字串物件

常用的定義字串物件的方法是 string int 當同乙個物件需進行多次定義的時候,除了第一次,剩下的可直接定義 例如 int i 1 第二次 i 2 public int indexof 是尋找所需內容第一次出現的位置 public int lastindexof 是尋找所需內容最後一次出現的位置...

字串物件

建立物件 var s aada adds afsd fs f xx 直接建立乙個物件屬性 length length 得到字串的長度 返回的是乙個字串 綠色的 length 是乙個屬性 console.log s.length 結果為 15方法 charat 索引位置 console.log s.c...