Core Function StrSplit

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> StrSplit( <expression>, <split_length>, <flag> ) </pre> === Description === Convert a string to an array === Parameters === ==== expression ==== The input string. ===...")
 
(flag)
Line 30: Line 30:
  
 
1 | 2
 
1 | 2
 +
 +
If just flag 1 is given the split will be \n
  
 
=== Return Value ===
 
=== Return Value ===

Revision as of 10:31, 29 January 2013

StrSplit( <expression>, <split_length>, <flag> )

Contents

Description

Convert a string to an array

Parameters

expression

The input string.

split_length

Optional; Maximum length of the chunk.

flag

Optional; Flag to choose return type.

1 = Return as a string instead of array

2 = Use \n at the splits

4 = Use \r a the splits

You can add flags together for example to split at strings on \n you do:

1 | 2

If just flag 1 is given the split will be \n

Return Value

Success: Returns the extracted string/array (Depending on flag).

Failure: Returns an empty string/array (Depending on flag).

Remarks

If the optional split_length parameter is specified, the returned array will be broken down into chunks with each being split_length in length, otherwise each chunk will be one character in length.

Example

$str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" x 20;
printr strsplit($str, 4);


$str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" x 20;
printr strsplit($str, 4, 1);


$str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" x 20;
printr strsplit($str, 4, 1 | 2);


$str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" x 20;
printr strsplit($str, 4, 1 | 2 | 4);
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox