2012-07-07

VBScript函數--字元字串處理--Right取得指定字串自右算起指定字元數長度的字串

Right → 取得指定字串自右算起的指定字元數長度的字串
語法:Right(string,length)

函數字串字元數執行函數寫法結果訊息
Right0001233Right("000123",3)123
Right
(如無法正常測試,建議使用IE瀏覽器)
<script language="vbscript">
  <!--
    sub run_Right()
        document.all("lblRight").innerHTML = ""
        if isNumeric(trim(document.all("Right2").value))  then
            if CDBL(trim(document.all("Right2").value)) >=0  then
                document.all("Right3").innerHTML = "Right(" & chr(34) & document.all("Right1").value & chr(34) &_
                "," & trim(document.all("Right2").value) & ")"
                document.all("Right4").value = Right(document.all("Right1").value,trim(document.all("Right2").value))
                document.all("lblRight").innerHTML = "已取得字串!"
            else
                document.all("lblRight").innerHTML = "字元數=" & document.all("Right2").value & ",請輸入≧0的整數!"
                document.all("Right3").innerHTML = ""
                document.all("Right4").value = ""
                document.all("Right2").value = ""
                document.all("Right2").focus
            end if
        else
            document.all("lblRight").innerHTML = "字元數=" & document.all("Right2").value & ",請輸入≧0的整數!"
            document.all("Right3").innerHTML = ""
            document.all("Right4").value = ""
            document.all("Right2").value = ""
            document.all("Right2").focus
        end if
    end sub
  -->
</script>
<br />
<table>
<tbody>
<tr>
    <td>函數</td><td>字串</td><td>字元數</td><td>執行</td><td>函數寫法</td><td>結果</td><td>訊息</td>
</tr>
<tr>
    <td>Right</td>
    <td><input id="Right1" name="Right1" type="text" style="width:80px"/></td>
    <td><input id="Right2" name="Right2" type="text" style="width:25px"/></td>
    <td><input id="btnRight" name="btnRight" onclick="run_Right()" type="button" value="Run" /></td>
    <td><label id="Right3" name="Right3"></label></td>
    <td><input id="Right4" name="Right4" type="text" style="width:80px" readonly/></td>
    <td><label id="lblRight" name="lblRight"></label></td>
</tr>
</tbody> 
</table>

沒有留言:

張貼留言