用vb怎樣刪除文字每行前面的空格

時間 2022-05-30 10:40:05

1樓:匿名使用者

private sub command1_click()

'僅去掉每一行前面的空格

dim ary() as string

dim i as long

me.list1.clear

ary = split(me.text1.text, vbcrlf)

text1 = ""

for i = lbound(ary) to ubound(ary)

text1 = text1 & ltrim(ary(i)) & vbcrlf

next

end sub

private sub command2_click()

'去掉全部空格

text1.text = replace(replace(text1.text, vbtab, ""), " ", "")

end sub

private sub command3_click()

'去掉所有空行

do while instr(text1.text, vbcrlf & vbcrlf) > 0

text1.text = replace(text1.text, vbcrlf & vbcrlf, vbcrlf)

loop

end sub

private sub form_load()

'在text1中產生幾個有前導空格的資料。

for i = 1 to 10

text1 = text1 & chr(13) & chr(10) & string(int(rnd * 5), " ") & 5 * i & ","

next i

end sub

2樓:匿名使用者

private sub command1_click()'textbox中所有的tab和空格都被清除掉了。

text1.text = replace(replace(text1.text, vbtab, ""), " ", "") '用一下一樓的**啊,謝謝了

'去空行

dim arr() as string,ss as stringdim i as integer

arr = split(text1.text, vbcrlf)for i = 0 to ubound(arr)if trim(replace(arr(i), " ", "")) <> "" then ss = ss & vbcrlf & arr(i)

next

text1.text = mid(ss, 3)end sub

3樓:

直接用trim()函式可以去除開頭和結尾的空著

vb 刪除文字框每行開頭的空格和結尾的空格怎麼弄? 10

4樓:匿名使用者

text1.text = trim(text1.text)

5樓:二兩牛肉不要面

private sub command1_click()dim stmp as string

dim slist() as stringdim ii as long

stmp = text1.text

slist = split(stmp, vbcrlf)text1.text = ""

for ii = 0 to ubound(slist)text1.text = text1.text & trim(slist(ii)) & vbcrlf

next

end sub

vb 刪除文字空格行

6樓:匿名使用者

dim tmpstr

dim resstr as string'處理bai後的字元du串zhi

tmpstr=split(text1.text,vbcrlf)for i=lbound(tmpstr) to ubound(tmpstr)

if trim(tmpstr(i))<>"" thenresstr=resstr & tmpstr(i) & vbcrlfend if

next

print resstr'顯示處理後

的字串

假設 字串都在dao text1.text 中這種處理只適用於內一般的簡單情容況,還會出現其他情況,如果你遇見了就追問。

7樓:寶之小小葉

private sub commandbutton1_click()

dim str as string '處理完後放回textbox的字串

dim arr() as string

arr = split(textbox1.value, vbcrlf) '通過換行符分割textbox內的文字

for i = 0 to ubound(arr)

if trim(arr(i)) <> "" then

str = str & arr(i) & vbcrlf '迴圈遍歷,如果改行不是空行,則回講陣列內文字拼接到輸答出用字串變數

end if

next i

textbox1.value = str '講新字串放回textbox

end sub

8樓:領奴三千

dim tmpstr() as stringtmpstr = split(textbox1.text, vbcrlf)

textbox1.text = ""

for i = 0 to ubound(tmpstr)if tmpstr(i) <> "" thentextbox1.text = textbox29.text & tmpstr(i) & vbcrlf

end if

next

vb如何去掉每行的兩邊空格部分?

9樓:匿名使用者

不能一次問完啊!

sstr = trim (sstr)

vb6如何判斷並刪除字串首行的空行或空格。

10樓:匿名使用者

刪除行首、行尾空格可用trim、ltrim、rtrim函式

刪除空行,可以讀取一行並判斷它是否為「」,是,接著讀下一行。

怎樣用vb刪除txt文字檔案中每行24個字元之後的字元(每行只保留前24個字元)?

11樓:匿名使用者

解決的思路:

先讀出來,然後處理,最後寫回檔案。

採用left()函式,可以取出每行左邊的24個字元。

怎樣一下子刪除word文件每行內容前面的空格

12樓:匿名使用者

如下:1、如果前面確實是空格,可以複製這個空格。

2、之後按ctrl+h 替換。

3、貼上到查詢內容中,點選全部替換即可。

4、如果是首先縮排,可以全選,設定段落,無縮排。

13樓:深圳市勵拓軟體****

用word的查詢替換功能

ctrl+h調出替換介面,在「查詢內容」裡輸入乙個空格,然後單擊「全部替換」即可

vb如何刪除乙個字串的所有空格和換行符

14樓:匿名使用者

private sub command1_click()dim a as string, b as stringdim i as long, j as long, k as long

a = "abcdef 77 8e9"

b = ""

k = len(a)

for i = 1 to k

j = asc(mid(a, i))

if j <> 10 and j <> 13 and j <> 32 and j <> asc(" ") then '最後乙個條件是全形空格

b = b & chr(j)

end if

next

print a

print b

end sub

'呵呵,小弟學藝不精,replace函式以前還真不知道,vb6下當然是用replace了。

15樓:匿名使用者

樓上兩個均為正解,

只是,二樓的,對vb5無效

而一樓的,不受限制!

16樓:

strtext = replace(strtext, chr(32), "")

strtext = replace(strtext, chr(13), "")

strtext = replace(strtext, chr(10), "")

試驗了好多次了,應該沒問題

17樓:

那個全形的空格是不是也應該一起過濾了

vb用sub過程計算5 4陣列中每行最大元素及位置

假設陣列是 dim k 1 to 5,1 to 4 as single dim maxx as integer,maxy as integer sub findmax dim i as integer,j as integerdim tempmax as singletempmax 1.401298...

怎樣用VB做個編寫程式,在文字框中顯示當前系統時間,並隨時間進行變化

你新增一個timer控制元件 interval屬性 100 新增事件 private sub timer1 timer text1.text format now,hh mm ss end sub private sub form load timer1.enabled trueend sub pr...

用VB控制excel刪除特定的單元格

sub 清除 for each rng in range a1 z10 if rng 位置 then range cells rng.row,rng.column 1 cells rng.row,rng.column 5 rng.offset 1,0 end if next end sub priv...