跳轉到內容

Futurebasic/語言/參考/MID 語句

來自華夏公益教科書,自由的教科書

MID$ 和 MID$$

[編輯 | 編輯原始碼]

MID$(stringVar$,startPos,numChars) = replaceString$ MID$$(container$$,startPos,numChars) = ¬   replaceString$/contnr$$

2000 年 5 月 30 日(釋出 3)

此語句更新 stringVar$(必須是字串變數)或 container$$ (容器變數),刪除 stringVar$ container$$ 中的一部分,並用 replaceString$ 左側相同數量的字元替換它。要替換的部分從 stringVar$ container$$ 中的 startPos 位置開始。在以下程式碼片段中,容器和字串的工作方式相同。替換的字元數等於以下數量中最小的一個

  • numChars
  • LEN(replaceString$)
  • LEN(stringVar$) - startPos + 1

在以下情況下,MID$ 不執行任何操作

  • stringVar$replaceString$ 為空時;
  • startPos 小於 1 或大於 LEN(stringVar$) 時;
  • numChars 小於 1 時。

注意: 您不能在等號右側使用包含容器的複雜表示式。

示例: x$ = "abcdefgh" y$ = "abcdefgh" z$ = "abcdefgh" MID$(x$,2,3) = "1234" PRINT x$ MID$(y$,2,5) = "1234" PRINT y$ MID$(z$,7,4) = "1234" PRINT z$

程式輸出
a123efgh a1234egh abcdef12

MID$ 函式; LEFT$; RIGHT$; INSTR

華夏公益教科書