Core Function CountWords

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> CountWords( <string> ) </pre> === Description === Return information about words used in a string . === Parameters === ==== char ==== An ASCII code in the range 0-255 ...")
 
Line 1: Line 1:
 
<pre>
 
<pre>
CountWords( <string> )
+
CountWords( <string>, <format>, <charlist> )
 
</pre>
 
</pre>
  
 
=== Description ===
 
=== Description ===
  
Return information about words used in a string .
+
Return information about words used in a string.
  
 
=== Parameters ===
 
=== Parameters ===
  
==== char ====
+
==== string ====
  
An ASCII code in the range 0-255 (e.g., 65 returns the capital letter A).
+
The string to use.
 +
 
 +
==== format ====
 +
 
 +
Specify the return value of this function. The current supported values are:
 +
 
 +
0 - returns the number of words found
 +
 
 +
1 - returns an array containing all the words found inside the string
 +
 
 +
2 - returns an associative array, where the key is the numeric position of the word inside the string and the value is the actual word itself
 +
 
 +
==== charlist ====
 +
 
 +
A list of additional characters which will be considered as 'word'
  
 
=== Return Value ===
 
=== Return Value ===
  
Success: Returns a string containing the ASCII representation of the given code.  
+
Success: Returns an array or an integer, depending on the format chosen.  
  
Failure: Returns a blank string.
+
Failure: Returns null.
  
 
=== Remarks ===
 
=== Remarks ===

Revision as of 20:48, 26 July 2014

CountWords( <string>, <format>, <charlist> )

Contents

Description

Return information about words used in a string.

Parameters

string

The string to use.

format

Specify the return value of this function. The current supported values are:

0 - returns the number of words found

1 - returns an array containing all the words found inside the string

2 - returns an associative array, where the key is the numeric position of the word inside the string and the value is the actual word itself

charlist

A list of additional characters which will be considered as 'word'

Return Value

Success: Returns an array or an integer, depending on the format chosen.

Failure: Returns null.

Remarks

None

Example

// Display how many words are found
my $Str = "The quick brown fox";
echo CountWords($Str), @NL;
// Prints 4
 
 
// Return an array containing all the words found inside the string
my $Str = "The quick brown fox";
printr CountWords($Str, 1);
// Prints
// ARRAY
// {
//         [0] => The
//         [1] => quick
//         [2] => brown
//         [3] => fox
// }
 
// Return an associative array, where the key is the numeric position
// of the word inside the string and the value is the actual word itself 
my $Str = "The quick brown fox";
printr CountWords($Str, 2);
// Prints
// ARRAY
// {
//        [0] => The
//        [4] => quick
//        [10] => brown
//        [16] => fox
// }
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox