Main Index : Reference :

strset()


Description

Fills a specified number of bytes in a string from a given position with a certain character.

Definition

[string] strset([string] str,[int] char,[int] pos,[int] num)

Parameters

str is the original string.
char is the character to fill with, given in 16 bit Unicode..
pos is the starting position of the filling.
num is the number of times that the character is repeated. (num >= 0)

Return Value

strset() returns a copy of str that is filled from position pos to position pos+num with the character char. The length of the return value is always the length of str. If any position of the specified fill interval is outside of str, for example if pos+num is greater than the length of str, it is simply disregarded. The starting position, pos, can be negative.

Remember: The first character of a string is at position 0.

The Unicode value of a character may be obtained by writing it like this: "a"[0]. One can also write a 16 bit hexadecimal Unicode value directly like this: 0x20AC

Example

// Outputs "ab---fghij"

var str  = "abcdefghij";
var char = "-"[0]
var pos  = 2;
var len  = 3;

println(strset(str,char,pos,len));


// Outputs "----efghij"

var str  = "abcdefghij";
var char = "-"[0]
var pos  = -2;
var len  = 6;

println(strset(str,char,pos,len));


// Outputs "abcdefg---"

var str  = "abcdefghij";
var char = "-"[0]
var pos  = 7;
var len  = 6;

println(strset(str,char,pos,len));

See Also

[string], strins(), strmid(), stradd(), strstr(), strchr(), strcmp()