2017-06-19 98 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 
相关问题