Core Function Reverse

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> Reverse( <expression> ) </pre> === Description === Reverse all characters in a string. === Parameters === ==== expression ==== The string to use. === Return Value ===...")
 
(Example)
 
(5 intermediate revisions by one user not shown)
Line 28: Line 28:
 
$str = "The quick brown fox";
 
$str = "The quick brown fox";
 
MsgBox(    Reverse($str)      );
 
MsgBox(    Reverse($str)      );
 +
</syntaxhighlight>
 +
 +
Modify the string in place
 +
<syntaxhighlight lang="sputnik">
 +
$value = "Hello";
 +
Println($value); // Prints Hello
 +
// Modify the string in place
 +
my $length = StrLen($value);
 +
for (my $i = 0, $j = $length - 1; $i < $j; $i++, $j--)
 +
{
 +
my $c = $value[$i];
 +
$value[$i] = $value[$j];
 +
$value[$j] = $c;
 +
}
 +
// All done
 +
Println($value); // Prints olleH
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Latest revision as of 09:58, 19 September 2015

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
my $length = StrLen($value);
for (my $i = 0, $j = $length - 1; $i < $j; $i++, $j--)
{
	my $c = $value[$i];
	$value[$i] = $value[$j];
	$value[$j] = $c;
}
// All done
Println($value); // Prints olleH
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox