Core Function ChunkSplit

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> ChunkSplit( <body>, <chunklen>, <end> ) </pre> === Description === Split a string into smaller chunks. === Parameters === ==== body ==== The string to be chunked. ==...")
 
m (1 revision)
 
(2 intermediate revisions by one user not shown)
Line 44: Line 44:
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
 
$string = '1234';
 
$string = '1234';
say substr(chunk_split($string, 2, ':'), 0, -1);
+
say substr(ChunkSplit($string, 2, ':'), 0, -1);
 
// will return 12:34 instead of 12:34:
 
// will return 12:34 instead of 12:34:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Latest revision as of 12:37, 14 June 2015

ChunkSplit( <body>, <chunklen>, <end> )

Contents

Description

Split a string into smaller chunks.

Parameters

body

The string to be chunked.

chunklen

The chunk length.

end

The line ending sequence.

Return Value

Success: Returns the chunked string.

Failure: Returns null.

Remarks

None

Example

$string = '1234'; 
say ChunkSplit($string, 2, ':'); // Prints 12:34:
 
$string = '123'; 
say ChunkSplit($string, 2, ':'); // Prints 12:3

The best way to solve the problem (if its a problem for you) with the last string added by ChunkSplit() is:

$string = '1234';
say substr(ChunkSplit($string, 2, ':'), 0, -1);
// will return 12:34 instead of 12:34:
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox