Results 1 to 2 of 2

Thread: php code to vb.net?

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2006
    Posts
    39

    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

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: php code to vb.net?

    vb Code:
    1. Public Function spin(ByVal str As String) As String
    2.         Static RNG As New Random(Now.Millisecond)
    3.  
    4.         Dim matches As Array = Regex.Split(str, "{(.+?)}")
    5.  
    6.         ' Discard if no matches
    7.         If matches.Length <= 1 Then Return str
    8.  
    9.         Dim match As String = matches(1)
    10.         Dim i As Integer = InStr(match, "{")
    11.         If i <> 0 Then
    12.             match = Mid(match, i + 1)
    13.         End If
    14.  
    15.         Dim parts As Array = match.Split("|")
    16.  
    17.         ' Random index
    18.         i = RNG.Next(0, parts.Length)
    19.  
    20.         ' Construct new string
    21.         str = Regex.Replace(str, "{" & Regex.Escape(match) & "}", parts(i))
    22.  
    23.         Return spin(str)
    24.     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
  •  



Click Here to Expand Forum to Full Width