TriggerHappy
...
- Reaction score
- 341
Strings Library
TriggerHappy187
Basic Overview:
This system is mean to extend the functions of strings in warcraft. It provides a few new usefull features that aren't already included.
Documentation:
JASS:
*----------------------*--------------------*
| Strings System | ClanMapz.com |
| by | TheHelper.net |
| TriggerHappy187 |--------------------*
| | Version 1.00 |
| | Alpha |
*----------------------*--------------------*
*--------------------------------------------*
|This system is mean to extend the functions |
|of strings in warcraft. It provides a few |
|new usefull features that arent already |
|inlcuded. This is the documentation for |
|this system - TriggerHappy187 |
*--------------------------------------------*
# function stripWord takes string full, string word returns string
//This function removes all the instances of a certain word from
// a string.
# function stringReplace takes string full, string word, string replacement returns string
//This function replaces all the words in a string with the replacement argument.
# function stringColorRGB takes string full, integer red, integer green, integer blue returns string
//This function colors a string using RGB Color codes, the same way you would color units
//in the object editor.
# function stringColor takes string full, string color returns string
//This function colors a string with your own color codes
//or with one of the pre-defined constant color codes
//in the globals.
# function stringRepeat takes string full, integer repeat returns string
//This function repeats a string how ever many times you want
# function wordCount takes string full returns integer
//Counts the number of words in a string
# function stringOcc takes string full, string word returns integer
//Counts the number of times a word is in a string
# function int2Hex takes integer int returns string
//Converts a integer into a hexidecimal string
# function stringRev takes string full returns string
//Reverses a string
The System:
JASS:
library Strings
globals
constant string color_red = "|c00FF0303"
constant string color_blue = "|c000042FF"
constant string color_teal = "|c001CE6B9"
constant string color_purple = "|c000042FF"
constant string color_yellow = "|c00FFFC01"
constant string color_orange = "|c00FEBA0E"
constant string color_green = "|c0020C000"
constant string color_pink = "|c00E55BB0"
constant string color_grey = "|c00959697"
constant string color_lightblue = "|c007EBFF1"
constant string color_darkgreen = "|c00106246"
constant string color_brown = "|c004E2A04"
endglobals
function stripWord takes string full, string word returns string
local integer i = 0
local integer length = StringLength(word)
local string output = full
loop
exitwhen i > StringLength(full)
if SubString(output, i, i + length) == word then
set output = SubString(output, 0, i) + SubString(output, i + length, length)
endif
set i = i + 1
endloop
return output
endfunction
function stringReplace takes string full, string word, string replacement returns string
local integer i = 0
local integer length = StringLength(word)
local integer replen = StringLength(replacement)
local string output = full
loop
exitwhen i > StringLength(full)
if SubString(output, i, i + length) == word then
set output = SubString(output, 0, i) + replacement + SubString(output, i + length, StringLength(output))
endif
set i = i + 1
endloop
return output
endfunction
function stringColorRGB takes string full, integer red, integer green, integer blue returns string
local string hex = "0123456789ABCDEF"
local string hred = ""
local string hgreen = ""
local string hblue = ""
local integer temp = 0
set temp = red/16
set hred = SubString(hex, temp, temp + 1)
set temp = red - (16*temp)
set hred = hred + SubString(hex, temp, temp + 1)
set temp = green/16
set hgreen = SubString(hex, temp, temp + 1)
set temp = green - (16*temp)
set hgreen = hgreen + SubString(hex, temp, temp + 1)
set temp = blue/16
set hblue = SubString(hex, temp, temp + 1)
set temp = blue - (16*temp)
set hblue = hblue + SubString(hex, temp, temp + 1)
return "|cFF" + hred + hgreen + hblue + full + "|r"
endfunction
function stringColor takes string full, string color returns string
return color + full + "|r"
endfunction
function stringRepeat takes string full, integer repeat returns string
local integer i = -1
local string output = full
loop
exitwhen i == repeat
set output = output + full
set i = i + 1
endloop
return output
endfunction
function wordCount takes string full returns integer
local integer i = 0
local integer count = 1
loop
exitwhen i > StringLength(full)
if SubString(full, i, i + 1) == " " and SubString(full, i-1, i) != " " then
set count = count + 1
endif
set i = i + 1
endloop
return count
endfunction
function stringOcc takes string full, string word returns integer
local integer i = 0
local integer occur = 0
loop
exitwhen i > StringLength(full)
if SubString(full, i, i + 1) == word then
set occur = occur + 1
endif
set i = i + 1
endloop
return occur
endfunction
function int2Hex takes integer int returns string
local string hex = "0123456789ABCDEF"
local integer temp = 0
local string output = ""
set temp = int/16
set output = SubString(hex, temp, temp + 1)
set temp = int - (16*temp)
set output = output + SubString(hex, temp, temp + 1)
return output
endfunction
function stringRev takes string full returns string
local integer i = StringLength(full)
local string output = ""
loop
exitwhen i <= 0
set output = output + SubString(full, i - 1, i)
set i = i - 1
endloop
return output
endfunction
endlibrary