Core Function Unescape

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> Unescape( <expression> ) </pre> === Description === Remove all escapes from a string. === Parameters === ==== expression ==== The string to use. === Return Value === ...")
 
m (1 revision)
 
(6 intermediate revisions by one user not shown)
Line 1: Line 1:
 
<pre>
 
<pre>
Unescape( <expression> )
+
Unescape( <expression>, <custom> )
 
</pre>
 
</pre>
  
Line 12: Line 12:
  
 
The string to use.
 
The string to use.
 +
 +
==== custom ====
 +
 +
Optional; A string containing characters to be unescaped instead of unescaping everything.
  
 
=== Return Value ===
 
=== Return Value ===
Line 21: Line 25:
 
=== Remarks ===
 
=== Remarks ===
  
None.
+
This removes all escapes from a string regardless if the escape is valid or not so even \# will be replaced with #.
 +
 
 +
If you require more specific escape/unescape functions see the ones that deal with C/Sputnik specific escapes.
  
 
=== Example ===
 
=== Example ===
  
 +
Unescape everything
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
 
say Unescape(@"\m\n\t\\");// Prints: mnt\
 
say Unescape(@"\m\n\t\\");// Prints: mnt\
 +
</syntaxhighlight>
 +
 +
Unescape only \t and \n
 +
<syntaxhighlight lang="sputnik">
 +
say Unescape(@"\nHello\tTest\p \Ok", 'tn');
 +
// Prints: nHellotTest\p \Ok
 +
</syntaxhighlight>
 +
 +
Unescape only A to Z
 +
<syntaxhighlight lang="sputnik">
 +
say Unescape(@"\H\e\l\l\o \W\o\r\l\d\!", 'A'..'Z');
 +
// Prints: H\e\l\l\o W\o\r\l\d\!
 +
</syntaxhighlight>
 +
 +
Unescape only A to Z and a to z
 +
<syntaxhighlight lang="sputnik">
 +
say Unescape(@"\H\e\l\l\o \W\o\r\l\d\!", 'A'..'Z' . 'a'..'z');
 +
// Prints: Hello World\!
 +
</syntaxhighlight>
 +
 +
Unescape using all AlphaNumeric characters
 +
<syntaxhighlight lang="sputnik">
 +
say Unescape(@"\H\e\l\l\o \W\o\r\l\d\!", @AlphaNumeric);
 +
// Prints: Hello World\!
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Latest revision as of 12:37, 14 June 2015

Unescape( <expression>, <custom> )

Contents

Description

Remove all escapes from a string.

Parameters

expression

The string to use.

custom

Optional; A string containing characters to be unescaped instead of unescaping everything.

Return Value

Success: Returns a string with backslashes stripped off. (\' becomes ' and so on.) Double backslashes (\\) are made into a single backslash (\).

Failure: Returns empty string.

Remarks

This removes all escapes from a string regardless if the escape is valid or not so even \# will be replaced with #.

If you require more specific escape/unescape functions see the ones that deal with C/Sputnik specific escapes.

Example

Unescape everything

say Unescape(@"\m\n\t\\");// Prints: mnt\

Unescape only \t and \n

say Unescape(@"\nHello\tTest\p \Ok", 'tn');
// Prints: nHellotTest\p \Ok

Unescape only A to Z

say Unescape(@"\H\e\l\l\o \W\o\r\l\d\!", 'A'..'Z');
// Prints: H\e\l\l\o W\o\r\l\d\!

Unescape only A to Z and a to z

say Unescape(@"\H\e\l\l\o \W\o\r\l\d\!", 'A'..'Z' . 'a'..'z');
// Prints: Hello World\!

Unescape using all AlphaNumeric characters

say Unescape(@"\H\e\l\l\o \W\o\r\l\d\!", @AlphaNumeric);
// Prints: Hello World\!
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox