2017-06-19 97 views
0

我有[email protected]我想從這個字符串中獲得「myword」怎麼做?asp經典如何在一個字符串後面帶一個字或一個字符後的特定符號@

發現這一點,但不知道如何轉換爲ASP

String res = email.substring(email.indexOf("@") + 1); 

我知道如何使用LEN左中部和右劈,我相信答案是這些功能的遊戲,但我沒有發現在我的搜索中回答如何。

還是否有人知道如何用正則表達式做這樣一個模式(剛開始工作)大加讚賞

感謝所有幫助:)

回答

0

花了一些時間和一些嘗試,但我發現:)

[email protected] 
response.write mid(email,(inStr(email, "@"))+1,1) 
2

雖然this other answer是沒有錯的和「@」後,將返回的第一個字母,還有一個更通用的方法。對於這一點,我將使用一個分割字符串與多個部件的功能,同時基於「從」和「到」定界符:

Function GetBetween(str, leftDelimeter, rightDelimeter) 
    Dim tmpArr, result(), x 
    tmpArr=Split(str, leftDelimeter) 
    If UBound(tmpArr) < 1 Then 
     GetBetween=Array() : Exit Function 
    End If 
    ReDim result(UBound(tmpArr)-1) 
    For x=1 To UBound(tmpArr) 
     result(x-1)=(Split(tmpArr(x), rightDelimeter))(0) 
    Next 
    Erase tmpArr 
    GetBetween=result 
End Function 

現在,在這個specfic情況下使用它,有這樣的代碼:

Dim email, tempArray 
email = "[email protected]" 

'find the word between the "@" and the first dot 
tempArray = GetBetween(email, "@", ".") 

'check that we got anything: 
If UBound(tempArray)<0 Then 
    Response.Write("invalid email") 
Else 
    'desired word is the first item in the array: 
    Response.Write(tempArray(0)) 
End If 

'free allocated memory for dynamic array: 
Erase tempArray 
相關問題