返回乙個整數,該整數指定乙個字串在另乙個字串中的第乙個匹配項的起始位置。 如果找到了匹配項,則該整數是從 1 開始的索引。 如果未找到匹配項,則函式返回零。
控制項屬性值控制項
屬性值textbox
name
txttext
button
name
btnsearch
multiline
true
text
查詢hideselection
false
button
name
btnraplace
size
288,232
text
替換location
0,0button
name
btnexit
text
退出
public class form1
private sub form1_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load
txttext.text = "hello,how are you."
end sub
public function findword(byval substring as string) as boolean
dim textstring as string = txttext.text
if substring.equals("") then
return false
end if
dim startposition as integer
startposition = instr(textstring, substring)
if startposition > 0 then
txttext.selectionstart = startposition - 1
txttext.selectionlength = len(substring)
return true
else
return false
end if
end function
private sub btnsearch_click(byval sender as system.object, byval e as system.eventargs) handles btnsearch.click
dim results as boolean
dim substring as string
substring = trim(inputbox("輸入要查詢的字串", "查詢", txttext.selectedtext))
if substring.equals("") then
exit sub
end if
msgbox("要查詢的字串是:" & substring)
results = findword(substring)
if not results then
msgbox("文字框中沒有要找的字串")
end if
end sub
private sub btnreplace_click(byval sender as system.object, byval e as system.eventargs) handles btnreplace.click
dim result as boolean
dim substring as string
if txttext.selectedtext.equals("") then
substring = trim(inputbox("輸入要查詢的字串", "替換", txttext.selectedtext))
result = findword(substring)
if not result then
msgbox("文字框中沒有要找的文字")
exit sub
end if
end if
substring = trim(inputbox("把找到的文字替換為", "替換", txttext.selectedtext))
if substring.equals("") then
exit sub
end if
txttext.selectedtext = substring
end sub
private sub btnexit_click(byval sender as system.object, byval e as system.eventargs) handles btnexit.click
me.close()
end sub
end class
記事本 查詢與替換
namespace 查詢 private void button1 click object sender,eventargs e 查詢 namespace 查詢 private form1 fuform 建立乙個form1型別的變數fuform用來接收 jishiben那個窗體 public fi...
c primer習題10 6 文字查詢程式
ifndef textquery h define textquery h include include include include include includeusing namespace std class text query setrun query const string co...
Python例項4 文字進度條
import time scale 10 print 執行開始 for i in range scale 1 a i b scale i c i scale 100 time.sleep 0.1 print format c,a,b print 執行結束 import time for i in r...