Core Function Reverse
From Sputnik Wiki
				
				
				(Difference between revisions)
				
																
				
				
								
				 (→Example)  | 
		 (→Example)  | 
		||
| Line 32: | Line 32: | ||
Modify the string in place  | Modify the string in place  | ||
<syntaxhighlight lang="sputnik">  | <syntaxhighlight lang="sputnik">  | ||
| − | $  | + | $value = "Hello";  | 
| − | + | Println($value); // Prints Hello  | |
| − | $  | + | // Modify the string in place  | 
| − | + | fixed ($s = $value)  | |
| − | //   | + | {  | 
| + | 	my $length = StrLen($value);  | ||
| + | 	for (my $i = 0, $j = $length - 1; $i < $j; $i++, $j--)  | ||
| + | 	{  | ||
| + | 		my $c = $s[$i];  | ||
| + | 		$s[$i] = $s[$j];  | ||
| + | 		$s[$j] = $c;  | ||
| + | 	}  | ||
| + | }  | ||
| + | // All done  | ||
| + | Println($value); // Prints olleH  | ||
</syntaxhighlight>  | </syntaxhighlight>  | ||
[[Category:Core Function]]  | [[Category:Core Function]]  | ||
Revision as of 17:48, 10 August 2014
Reverse( <expression> )
Contents | 
Description
Reverse all characters in a string.
Parameters
expression
The string to use.
Return Value
Success: Returns new string.
Failure: Returns old string.
Remarks
None.
Example
$str = "The quick brown fox"; MsgBox( Reverse($str) );
Modify the string in place
$value = "Hello"; Println($value); // Prints Hello // Modify the string in place fixed ($s = $value) { my $length = StrLen($value); for (my $i = 0, $j = $length - 1; $i < $j; $i++, $j--) { my $c = $s[$i]; $s[$i] = $s[$j]; $s[$j] = $c; } } // All done Println($value); // Prints olleH