JavaScript စာကြောင်းရှာဖွေမှု()
ဥပမာများ
"အပြာ" ကို ရှာပါ-
let text = "Mr. Blue has a blue house";
let position = text.search("Blue");
"အပြာ" ကို ရှာပါ
let text = "Mr. Blue has a blue house";
let position = text.search("blue");
/Blue/: ရှာဖွေရန်
let text = "Mr. Blue has a blue house";
let position = text.search(/Blue/);
/blue/: ရှာဖွေရန်
let text = "Mr. Blue has a blue house";
let position = text.search(/blue/);
စာလုံးအသေးကို အာရုံမခံနိုင်သော ရှာရန်-
let text = "Mr. Blue has a blue house";
let position = text.search(/blue/i);
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
နည်းလမ်း သည် search()
ပုံမှန်ဖော်ပြချက်တစ်ခုနှင့် string တစ်ခုနှင့် ကိုက်ညီသည်**
နည်းလမ်းသည် ပထမ search()
ပွဲ၏ အညွှန်း (တည်နေရာ) ကို ပြန်ပေးသည်။
search()
တူညီမှုမတွေ့ပါက နည်းလမ်း-1 ကို ပြန်ပေးသည် ။
search()
နည်းလမ်းသည် case sensitive ဖြစ်သည် ။
မှတ်ချက်
** ရှာဖွေမှုတန်ဖိုးသည် စာကြောင်းတစ်ကြောင်းဖြစ်ပါက၊ ၎င်းကို ပုံမှန်ဖော်ပြချက်အဖြစ်သို့ ပြောင်းသည်။
ကိုလည်းကြည့်ပါ-
အထားအသို
string.search(searchValue)
ကန့်သတ်ချက်များ
Parameter | Description |
searchValue | Required. The search value. A regular expression (or a string that will be converted to a regular expression). |
တန်ဖိုးကို ပြန်ပေးသည်။
ရိုက်ပါ။ | ဖော်ပြချက် |
နံပါတ်တစ်ခု | ပထမပွဲရဲ့ အနေအထားပါ။ -၁ ပွဲမရှိရင်။ |
String search() နှင့် String indexOf() အကြား ခြားနားချက်
စ search()
တင်သည့် အနေအထား အငြင်းအခုံကို မယူနိုင်ပါ။
နည်းလမ်း သည် indexOf()
ပုံမှန်အသုံးအနှုန်းကို ဆန့်ကျင်၍ ရှာဖွေမရနိုင်ပါ။
String search() နှင့် string match() အကြား ကွာခြားချက်
နည်းလမ်းသည် ပထမ search()
ပွဲ၏ အနေအထားကို ပြန်ပေးသည်။
နည်းလမ်း သည် match()
ကိုက်ညီမှုတစ်ခုအား ပြန်ပေးသည်။
ပုံမှန်ဖော်ပြမှုရှာဖွေရေးနည်းလမ်းများ
JavaScript တွင်၊ ပုံမှန် expression text search ကို မတူညီသောနည်းလမ်းများဖြင့် လုပ်ဆောင်နိုင်သည်။
ပုံမှန်အသုံးအနှုန်းအဖြစ် ပုံစံ တစ်ခု ဖြင့်၊ ဤအရာများသည် အသုံးအများဆုံးနည်းလမ်းများဖြစ်သည်-
ဥပမာ | ဖော်ပြချက် |
---|---|
text.match( ပုံစံ ) | String method သည် match() |
text.search( ပုံစံ ) | စာတန်းနည်းလမ်းရှာဖွေမှု() |
ပုံစံ .exec(စာသား) | RexExp နည်းလမ်း exec() |
ပုံစံ .test(စာသား) | RegExp နည်းလမ်းစမ်းသပ်မှု() |
Browser ပံ့ပိုးမှု
search()
ECMAScript1 (ES1) အင်္ဂါရပ်တစ်ခုဖြစ်သည်။
ES1 (JavaScript 1997) ကို ဘရောက်ဆာအားလုံးတွင် အပြည့်အဝ ပံ့ပိုးထားသည်။
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |