|
-
Jul 10th, 2010, 06:14 PM
#1
Thread Starter
Member
php code to vb.net?
Hi,
I want to post this to see if anyone can help me, I need to convert a php function into vb.net but I have no idea, here the function:
Code:
echo spin('{an {option|choice|right}|the basic} element');
function spin($s){
preg_match('#\{(.+?)\}#is',$s,$m);
if(empty($m)) return $s;
$t = $m[1];
if(strpos($t,'{')!==false){
$t = substr($t, strrpos($t,'{') + 1);
}
$parts = explode("|", $t);
$s = preg_replace("+\{".preg_quote($t)."\}+is", $parts[array_rand($parts)], $s, 1);
return spin($s);
}
I don't mind to move the question to the projects(to paid you) if you know the answer.
Thanks,
Diego
-
Jul 11th, 2010, 12:55 AM
#2
Re: php code to vb.net?
vb Code:
Public Function spin(ByVal str As String) As String Static RNG As New Random(Now.Millisecond) Dim matches As Array = Regex.Split(str, "{(.+?)}") ' Discard if no matches If matches.Length <= 1 Then Return str Dim match As String = matches(1) Dim i As Integer = InStr(match, "{") If i <> 0 Then match = Mid(match, i + 1) End If Dim parts As Array = match.Split("|") ' Random index i = RNG.Next(0, parts.Length) ' Construct new string str = Regex.Replace(str, "{" & Regex.Escape(match) & "}", parts(i)) Return spin(str) End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|