บทช่วยสอน ASP

ASP HOME

กวดวิชา WP

แนะนำหน้าเว็บ มีดโกนหน้าเว็บ เค้าโครงหน้าเว็บ โฟลเดอร์หน้าเว็บ หน้าเว็บทั่วโลก แบบฟอร์มหน้าเว็บ วัตถุหน้าเว็บ ไฟล์หน้าเว็บ ฐานข้อมูลหน้าเว็บ ผู้ช่วยหน้าเว็บ หน้าเว็บ WebGrid แผนภูมิหน้าเว็บ อีเมลหน้าเว็บ ความปลอดภัยของหน้าเว็บ เผยแพร่หน้าเว็บ ตัวอย่างหน้าเว็บ ชั้นเรียนของหน้าเว็บ

มีดโกน ASP.NET

แนะนำมีดโกน มีดโกนไวยากรณ์ มีดโกน C# ตัวแปร มีดโกน C# ลูป มีดโกน C# Logic ตัวแปรมีดโกน VB มีดโกน VB Loops มีดโกน VB Logic

ASP Classic

แนะนำ ASP ไวยากรณ์ ASP ตัวแปร ASP ขั้นตอน ASP เงื่อนไข ASP ASP วนรอบ แบบฟอร์ม ASP คุกกี้ ASP เซสชัน ASP แอปพลิเคชัน ASP ASP #รวม ASP Global.asa ASP AJAX อีเมล ASP ตัวอย่าง ASP

การอ้างอิง ASP

ฟังก์ชัน ASP VB คีย์เวิร์ด ASP VB การตอบสนอง ASP คำขอ ASP แอปพลิเคชัน ASP เซสชัน ASP เซิร์ฟเวอร์ ASP ข้อผิดพลาด ASP ASP FileSystem ASP TextStream ไดรฟ์ ASP ไฟล์ ASP โฟลเดอร์ ASP พจนานุกรม ASP ASP AdRotator ASP BrowserCap การเชื่อมโยงเนื้อหา ASP ตัวหมุนเนื้อหา ASP ASP Quick Ref

กวดวิชา ADO

แนะนำ ADO ADO Connect ชุดระเบียน ADO จอแสดงผล ADO แบบสอบถาม ADO ADO Sort เพิ่ม ADO ADO Update ADO ลบ สาธิต ADO ADO เร่งความเร็ว

วัตถุ ADO

คำสั่ง ADO การเชื่อมต่อ ADO ข้อผิดพลาด ADO ADO Field พารามิเตอร์ ADO ADO พร็อพเพอร์ตี้ บันทึก ADO ชุดระเบียน ADO ADO สตรีม ประเภทข้อมูล ADO

ฟังก์ชันแทนที่ VBScript


❮ การอ้างอิง VBScript ที่สมบูรณ์

ฟังก์ชันแทนที่แทนที่ส่วนที่ระบุของสตริงด้วยสตริงอื่นตามจำนวนที่ระบุ

ไวยากรณ์

Replace(string,find,replacewith[,start[,count[,compare]]])

Parameter Description
string Required. The string to be searched
find Required. The part of the string that will be replaced
replacewith Required. The replacement substring
start Optional. Specifies the start position. Default is 1. All characters before the start position will be removed.
count Optional. Specifies the number of substitutions to perform.
Default value is -1, which means make all possible substitutions
compare Optional. Specifies the string comparison to use. Default is 0

Can have one of the following values:

  • 0 = vbBinaryCompare - Perform a binary comparison
  • 1 = vbTextCompare - Perform a textual comparison

ตัวอย่าง

ตัวอย่าง 1

แทนที่คำว่า "สวย" ด้วย "มหัศจรรย์":

<%

txt="This is a beautiful day!"
response.write(Replace(txt,"beautiful","fantastic"))

%>

ผลลัพธ์ของโค้ดด้านบนจะเป็น:

This is a fantastic day!

ตัวอย่าง 2

แทนที่ตัวอักษร "i" ด้วย "##":

<%

txt="This is a beautiful day!"
response.write(Replace(txt,"i","##"))

%>

ผลลัพธ์ของโค้ดด้านบนจะเป็น:

Th##s ##s a beaut##ful day!

ตัวอย่างที่ 3

แทนที่ตัวอักษร "i" ด้วย "##" โดยเริ่มต้นที่ตำแหน่ง 15:

โปรดทราบว่าอักขระทั้งหมดก่อนตำแหน่ง 15 จะถูกลบออก

<%

txt="This is a beautiful day!"
response.write(Replace(txt,"i","##",15))

%>

ผลลัพธ์ของโค้ดด้านบนจะเป็น:

t##ful day!

ตัวอย่างที่ 4

แทนที่ 2 ตัวแรกของตัวอักษร "i" ด้วย "##" โดยเริ่มจากตำแหน่งที่ 1:

<%

txt="This is a beautiful day!"
response.write(Replace(txt,"i","##",1,2))

%>

ผลลัพธ์ของโค้ดด้านบนจะเป็น:

Th##s ##s a beautiful day!

ตัวอย่างที่ 5

แทนที่ตัวอักษร "t" ด้วย "##" ด้วยข้อความและไบนารีเปรียบเทียบ:

<%

txt="This is a beautiful day!"
response.write(Replace(txt,"t","##",1,-1,1) & "<br />")
response.write(Replace(txt,"t","##",1,-1,0))

%>

ผลลัพธ์ของโค้ดด้านบนจะเป็น:

##his is a beau##iful day!
This is a beau##iful day!

❮ การอ้างอิง VBScript ที่สมบูรณ์