TEIMSI
Developer's platform of programming text codes
Home|Utilities|Forum|Documentation

Table of contents -> Chapter 8 - Functions for string type variables


The next topic is the description for the use of the following TEIMSI predefined functions:

1)- asc

2)- ascat

3)- chr

4)- chrat

5)- hashver

6)- hextostr

7)- isinsideof

8)- ke_hashxlen

9)- lcase

10)- left

11)- len

12)- ltrim

13)- makestring

14)- replace

15)- right

16)- rtrim

17)- scrc16b

18)- setascat

19)- setchrat

20)- str_count

21)- str_repeatn

22)- str_overwrite

23)- str_reverse

24)- strpos

25)- strposrev

26)- strtohex

27)- substr

28)- substring

29)- trim

30)- ucase

31)- loadszstring




asc

The "asc" function, receives a character and returns its ASCII code, an integer between 0 and 255 (inclusive). It is the inverse function of the function chr.


Syntax
asc(string)
 

Parameters
string
TEIMSI variable with a data type of string and length of 1 byte.
 

Returned value
integer_number
TEIMSI variable with data type of a 32 bits integer number, not less than 0 nor greater than 255.
 

Example:



	alert(asc("@"))		//	Shows the integer 64.



See also <<chr>>


Go to top

ascat

The "ascat" function, returns the ASCII code of a character of a string sent to it.


Syntax
ascat(string, position)
 

Parameters
string
TEIMSI variable with a data type of string.
 
position
TEIMSI variable with data type of a 32 bits integer number (not less than 0 and not "greater or equal" than the length of the string).
 

Returned value
integer_number
TEIMSI variable with data type of a 32 bits integer number that contains the ASCII code of the character on that position.
 

Example:




	alert(ascat("Hello", 4))	//	Shows the ASCII code of the char "o", = 111



See also <<chrat>>, <<setchrat>>, <<setascat>>


Go to top

chr

The "chr" function, receives an integer between 0 and 255 (inclusive) and returns a character whose ASCII code is the number that was sent to it. It is the inverse function of the asc function.


Syntax
chr(integer_number)
 

Parameters
integer_number
TEIMSI variable with data type of a 32 bits integer number, not less than 0 nor greater than 255.
 

Returned value
string
TEIMSI variable with a data type of string, with length of 1 byte.
 

Example:



	alert(chr(65))		//	Shows the character "A".



See also <<asc>>


Go to top

chrat

The "chrat" function, returns a character located in the string sent to it.


Syntax
chrat(string, position)
 

Parameters
string
TEIMSI variable with a data type of string.
 
position
TEIMSI variable with data type of a 32 bits integer number, (not less than 0 and not "greater or equal" than the length of the string).
 

Returned value
string
TEIMSI variable with a data type of string, with length of 1 byte.
 

Example:




	alert(chrat("Hello",4))	//	Shows the character "o"



See also <<ascat>>, <<setchrat>>, <<setascat>>


Go to top

hashver

The "hashver" function, calculates a "hash" number (or CRC checksum) from a string that is sent as a parameter.


Syntax
hashver(string)
 

Parameters
string
TEIMSI variable with a data type of string.
 

Returned value
integer_number
TEIMSI variable with data type of a 32 bits integer number (between -2147483648 and 2147483647 included, that's one integer value of 4294967296 possible values) that represents a CRC of the string.
 

Example:



	alert(hashver("fire"))		//	Shows 1761614542



See also <<ke_hashxlen>>, <<scrc16b>>


Go to top

hextostr

The "hextostr" function, receives a string previously created with the strtohex function (it performs the inverse task that function).


Syntax
hextostr(string)
 

Parameters
string
TEIMSI variable with a data type of string.
 

Returned value
string
TEIMSI variable with a data type of string.
 

Example:



	var string1=strtohex("@$")	//	string1 has now the string "4024"

	alert(hextostr(string1))	//	Shows the string "@$".



See also <<strtohex>>, <<chr>>


Go to top

isinsideof

The "isinsideof" function, determines whether the first characters of a string match with those of another string that is also sent to it.


Syntax
isinsideof(string1, string2, start)
 

Parameters
string1
TEIMSI variable with a data type of string.
 
string2
TEIMSI variable with a data type of string, with a length less or equal than the length of 'string1'.
 
start
TEIMSI variable with data type of a 32 bits integer number (not less than 0 and not "greater or equal" than the length of the string), indicates the position from where starts the comparison of the content in "string2" within of "string1".
 

Returned value
boolean
TEIMSI variable with a data type of boolean (true or false).
 

The advantage of this function resides on the speed to determine if part of a string matches with other one, since other code doing this task will surely be much more slow. It's performance is notable when you need to call the function thousands of times per second.


Example:



	alert(isinsideof("017-Ocean - Dreams", "-Ocean", 3))

		//	Determines if the string "-Ocean" is within the string "017-Ocean - Dreams" starting 
		//		from the position 3 (true).



See also <<strpos>>


Go to top

ke_hashxlen

The "ke_hashxlen" function, returns a "hash" string (unique and not convertible to the source string by of reciprocal function), from the source string. It's the length of the output string can be specified and its characters can be on the whole range of the ASCII code (from 0 to 255 included).


Syntax
ke_hashxlen(string, amount)
 

Parameters
string
TEIMSI variable with a data type of string.
 
amount
TEIMSI variable with data type of a 32 bits integer number (not less than 0).
 

Returned value
string
TEIMSI variable with a data type of string.
 

The advantage of this function resides on its capability to return a "binary" string of arbitrary length, it also provides a "strong" method of calculation of the output string (and it is considerably slow).


Example:



	// Displays a "hash" string (similar to the one that generates the "MD5Hash" function, for more information search for "RFC1321" on the Internet).


	alert(strtohex(ke_hashxlen("Programming with TEIMSI", 16)))



See also <<hashver>>


Go to top

lcase

The "lcase" function, converts the characters of a string to lowercase.


Syntax
lcase(string)
 

Parameters
string
TEIMSI variable with a data type of string.
 

Returned value
string
TEIMSI variable with a data type of string, it's the string sent as parameter converted to lower case.
 

Example:



	alert(lcase("PROGRAM"))		//	Shows "program"


See also <<ucase>>


Go to top

left

The "left" function, returns a string with is part of the left side of the string that it receives.


Syntax
left(string, amount)
 

Parameters
string
TEIMSI variable with a data type of string.
 
amount
TEIMSI variable with data type of a 32 bits integer number (not less than 0). It's the length of the output string.
 

Returned value
string
TEIMSI variable with a data type of string.
 

Example:



	alert(left("UltraRay", 5))		//	Shows the string "Ultra".



See also <<right>>


Go to top

len

The "len" function, returns an integer with the length of a TEIMSI variable with a data type of string.


Syntax
len(string)
 

Parameters
string
TEIMSI variable with a data type of string.
 

Returned value
integer_number
TEIMSI variable with data type of a 32 bits integer number (not less than 0) with the length of the string.
 

Example:



	alert(len("number"))		//	Shows "6"


See also <<count>>


Go to top

ltrim

The "ltrim" function, receives a string and returns the result of removing spaces and tabs on its left side.


Syntax
ltrim(string)
 

Parameters
string
TEIMSI variable with a data type of string.
 

Returned value
string
TEIMSI variable with a data type of string.
 

Example:



	alert("This is a " + ltrim("	  	text"))		// Shows "This is a text"



See also <<rtrim>>, <<trim>>


Go to top

makestring

The "makestring" function, creates a string with the desired length, containing all the characters equal to the character with ASCII 0 which is chr(0).


Syntax
makestring(integer_number)
 

Parameters
integer_number
TEIMSI variable with data type of a 32 bits integer number (not less than 0) with the length of the string.
 

Returned value
string
TEIMSI variable with a data type of string.
 

Example:



	alert(len(makestring(29)))		// Shows "29"



See also <<str_repeatn>>


Go to top

replace

The "replace" function, returns a string which is the result of replacing inside the string it receives; all matches of a string for another.


Syntax
replace(mainstring, searchstr, replacestr)
 

Parameters
mainstring
TEIMSI variable with a data type of string.
 
searchstr
TEIMSI variable with a data type of string.
 
replacestr
TEIMSI variable with a data type of string.
 

Returned value
string
TEIMSI variable with a data type of string.
 

Example:



	alert(replace("ello", "e", "He"))



See also <<strpos>>


Go to top

right

The "right" function, returns a string with is part of the right side of the string it receives.


Syntax
right(string, amount)
 

Parameters
string
TEIMSI variable with a data type of string.
 
amount
TEIMSI variable with data type of a 32 bits integer number (not less than 0). It's the length of the output string.
 

Returned value
string
TEIMSI variable with a data type of string.
 

Example:



	alert(right("UltraRay", 3))		//	Shows the string "Ray".



See also <<left>>


Go to top

rtrim

The "rtrim" function, receives a string and returns the result of removing spaces and tabs on its right side.


Syntax
rtrim(string)
 

Parameters
string
TEIMSI variable with a data type of string.
 

Returned value
string
TEIMSI variable with a data type of string.
 

Example:



	alert("This is a " + rtrim("small	  	") + " text")		// Shows "This is a small text"



See also <<ltrim>>, <<trim>>


Go to top

scrc16b

The "scrc16b" function, creates a unique string (CRC) from another. The resulting string has four hexadecimal characters (numbers and letters A, B, C, D, E, F)


Syntax
scrc16b(string)
 

Parameters
string
TEIMSI variable with a data type of string.
 

Returned value
string
TEIMSI variable with a data type of string.
 

The function code written in P.H.P is the following:

		function s16b_crc($encs){
			$rslt = 799477;
			for($i=0;$i<strlen($encs);$i++){
				$rslt = $rslt ^ (ord($encs[$i])*175 + (($i*3+171)^7977) ) ;
			}
			$rslt=$rslt-65536*floor($rslt/65536);
			$rslt1=floor($rslt/256);
			$rslt2=$rslt-256*$rslt1;

			$s1="00".dechex($rslt1);
			$s2="00".dechex($rslt2);

			return( substr($s1, len($s1)-2, 2) . substr($s2, len($s2)-2, 2)     );
		}

	

Example:



	alert(scrc16b("hello"))		//	Shows "5B9F"


See also <<hashver>>


Go to top

setascat

The "setascat" function, returns a string that comes from writing a character in an input string, whose write position and character ASCII code is specified. Reading this value is done with the function ascat.


Syntax
setascat(string, position, number)
 

Parameters
string
TEIMSI variable with a data type of string.
 
position
TEIMSI variable with data type of a 32 bits integer number (not less than 0 and not "greater or equal" than the length of the string).
 
number
TEIMSI variable with data type of a 32 bits integer number that contains the ASCII code of the character to be written.
 

Example:




	var cad1="Oceani"

	setascat(cad1, 5, 111)

	alert(cad1)					//	Shows the string "Oceano".

	alert(setascat("Oceuno", 3, 97))		//	Shows the string "Oceano".



See also <<ascat>>, <<chrat>>, <<setchrat>>


Go to top

setchrat

The "setchrat" function, returns a string that comes from writing a character in an input string in a specified position writing. The reading of the character is done with the function chrat.


Syntax
setchrat(string, position, character)
 

Parameters
string
TEIMSI variable with a data type of string.
 
position
TEIMSI variable with data type of a 32 bits integer number (not less than 0 and not "greater or equal" than the length of the string).
 
character
TEIMSI variable with a data type of string, with length of 1 byte.
 

Example:



	var cad1="Oceani"

	setchrat(cad1, 5, "o")

	alert(cad1)					//	Shows the string "Oceano".

	alert(setchrat("Oceani", 5, "o"))		//	Shows the string "Oceano".


See also <<ascat>>, <<chrat>>, <<setascat>>


Go to top

str_count

The "str_count" function, receives two TEIMSI variables with string type and determines the number of times the second string is found within the first (except interpositions).


Syntax
str_count(string1, searchstr)
 

Parameters
string1
TEIMSI variable with a data type of string.
 
searchstr
TEIMSI variable with a data type of string, which is wanted to know how many times appears inside "string1".
 

Returned value
integer_number
TEIMSI variable with data type of a 32 bits integer number.
 

Example:


		alert(str_count("1111222211112222", "11"))		//	Show the number 4.



See also <<explode>>, <<implode>>


Go to top

str_repeatn

The "str_repeatn" function, creates a string repeating another input string whose number of repetitions is indicated by an integer as the first parameter.


Syntax
str_repeatn(string1, integer_number)
 

Parameters
string1
TEIMSI variable with a data type of string.
 
integer_number
TEIMSI variable with data type of a 32 bits integer number that contains the amount of times that the string will be repeated.
 

Returned value
string_output
TEIMSI variable with a data type of string.
 

Example:



	alert(str_repeatn("*", 12))		//	Shows the string "************"


See also <<str_count>>, <<makestring>>


Go to top

str_overwrite

The "str_overwrite" function, overwrites a portion of a string type variable. It receives as the first parameter a public variable or local to a TEIMSI function, and a second string type variable whose characters (bytes) will be written in the first one. The third parameter is a long integer (signed) with the displacement in the first string from where writing began. It support strings with length up to 2147483647 (That is, 2**31 - 1) bytes.


Syntax
str_overwrite(string1, string2, integer_number)
 

Parameters
string1
Public TEIMSI variable or local variable to a TEIMSI function. It must have dynamic mode, which means it must be the name of a variable and not the result of an expression.
 
string2
TEIMSI Variable which has the requirement of being a string variable.
 
integer_number
TEIMSI variable with data type of a 32 bits integer number that contains the offset to the starting position of the data writing on "string1".
 

Returned value
boolean
TEIMSI variable with a data type of boolean (true or false).
 

Example:



	var string1="wave of propagation"

	str_overwrite(string1, "in interaction", 5)

	alert(string1)

//Example 2

	//    The purpose of the function is to accelerate the process of replacing a partion of a string in TEIMSI language, it would otherwise be a slow task. As in the following example whose goal is to change the word "-center-" for "-string-" inside a known string variable. 

	var string1="left-center-right"

	var search  = "-center-"
	var change = "-string-"

	var p=strpos(string1, search, 0)

	//	Option 1 (slow)

		string1=substr(string1, 0, p) + change + substr(string1, p+len(search), -1)

	//	Option 2 (fastest)

		str_overwrite(string1, change, p)


See also <<substr>>, <<strpos>>


Go to top

str_reverse

The "str_reverse" function, receives a string and returns the string with all it's characters moved symmetrically respect of the center, (that is first characters appear as the last ones, and last characters as the first ones).


Syntax
str_reverse(string)
 

Parameters
string
TEIMSI variable with a data type of string.
 

Returned value
string
TEIMSI variable with a data type of string.
 

Example:



	alert(str_reverse("tol a"))		//	Shows the string "a lot"


See also <<str_repeatn>>


Go to top

strpos

The "strpos" function, seeks for a string within another starting from the specified position.


Syntax
strpos(string1, search, number)
 

Parameters
string1
TEIMSI variable with a data type of string. It's the string that has the search string.
 
search
TEIMSI variable with a data type of string. It is the string that function will search.
 
number
TEIMSI variable with data type of a 32 bits integer number that contains the starting position within "string1" where the search will begin.
 

Returned value
integer_number
TEIMSI variable with data type of a 32 bits integer number that indicates the position where is found the string "search" inside of "string1", or -1 if it was not found.
 

Example:



	alert(strpos("hello world", "ello", 0))		// Shows "1"
	alert(strpos("hello world", "ello", 2))		// Shows "-1"


See also <<strposrev>>


Go to top

strposrev

The "strposrev" function, searches for a string within another starting from the specified position from it's ending position to the starting position.


Syntax
strposrev(string1, search, integer_number)
 

Parameters
string1
TEIMSI variable with a data type of string. It is the string that contains the searched string.
 
search
TEIMSI variable with a data type of string. It is the string that function will search.
 
integer_number
TEIMSI variable with data type of a 32 bits integer number that contains the starting position within "string1" where the search will begin, it can be an integer greater or equal than the length of "string1": if it has a -1 value then it's handled as the length of that string.
 

Returned value
integer_number
TEIMSI variable with data type of a 32 bits integer number that indicates the position where is found the string "search" inside of "string1", or -1 if it was not found.
 

Example:



	alert(strposrev("hola ola.", "ola", 1000000))	// Shows "5"
	alert(strposrev("hola ola.", "ola", 3))		// Shows "1"



See also <<strpos>>


Go to top

strtohex

The "strtohex" function, converts a string into another whose ASCII codes are glued, using an hexadecimal notation and length of 2 bytes.


Syntax
strtohex(string)
 

Parameters
string
TEIMSI variable with a data type of string.
 

Returned value
string
TEIMSI variable with a data type of string.
 

Example:



	alert(strtohex("@$"))	//	Shows the string "4024", note that the ASCII code of "@" is 64 (or 40 hexadecimal) and the one of "$" is 36 (or 24 hexadecimal).



See also <<hextostr>>, <<chr>>


Go to top

substr

The "substr" function, subtracts part of a string. It is similar to the function substring but differs in the third parameter.


Syntax
substr(string, thestart, length)
 

Parameters
string
TEIMSI variable with a data type of string.
 
thestart
TEIMSI variable with data type of a 32 bits integer number (not negative). It indicates the starting position of the sub-string willing to be copied.
 
length
TEIMSI variable with data type of a 32 bits integer number (not negative). It indicates the length of the sub-string to be copied. If this value is -1, then the right side of the string from the position of the value of the second parameter ("thestart" number).
 

Returned value
string
TEIMSI variable with a data type of string.
 

Example:



	alert(substr("universe", 3, 5))		//	Shows the string "verse"



See also <<substring>>, <<left>>, <<right>>


Go to top

substring

The "substring" function, subtracts part of a string. It is similar to the function substr but differs in the third parameter.


Syntax
substring(string, thestart, theend)
 

Parameters
string
TEIMSI variable with a data type of string.
 
thestart
TEIMSI variable with data type of a 32 bits integer number (not negative). It indicates the starting position of the sub-string to be copied.
 
theend
TEIMSI variable with data type of a 32 bits integer number (not negative). It indicates the position that follows the ending character of the sub-string.
 

Returned value
string
TEIMSI variable with a data type of string.
 

Example:



	alert(substring("universe2", 3, 8))		//	Shows the string "verse"


See also <<substr>>, <<left>>, <<right>>


Go to top

trim

The "trim" function, removes spaces and tabs on the sides of an input string and returns the resulting string.


Syntax
trim(string)
 

Parameters
string
TEIMSI variable with a data type of string.
 

Returned value
string
TEIMSI variable with a data type of string.
 

Example:



	alert("The electron is " + trim("	  	a 		") + " lepton")		// Shows "The electron is a lepton"



See also <<ltrim>>, <<rtrim>>


Go to top

ucase

The "ucase" function, returns a string which is the result of convert the characters of the input string to uppercase.


Syntax
ucase(string)
 

Parameters
string
TEIMSI variable with a data type of string.
 

Returned value
string
TEIMSI variable with a data type of string, it's the string sent as parameter converted to upper case.
 

Example:



	alert(ucase("program"))		//	Shows "PROGRAM"



See also <<lcase>>


Go to top

loadszstring

The "loadszstring" function, loads a string defined in the assembler data section, the string must end with the character chr(0).


Syntax
loadszstring(integer_number)
 

Parameters
integer_number
TEIMSI variable with data type of a 32 bits integer. It must have the pointer to the string's address within the data section.
 

Returned value
string
TEIMSI variable with a data type of string. Returns the string defined within the data section excluding the character chr(0) that finishes it.
 

Example:



	place_idata{
		description db "The space is not empty.",0

	}
	var integer=0;
	_direct{
		mov [integer+reg.vo], (description)
	}
	alert(_c34+loadszstring(integer)+_c34);		//	Shows the string: "The space is not empty."



See also <<makestring>>


Go to top