1 of 1
Offline
Method to check if a given string can be typecast to a float. Use independently or add the method to your LSL preprocessor folder and add an include statement to your script.
#include "chkisfloat.lsl"
integer isFloat = ChkIsFloat (string inputString)
integer ChkIsFloat (string inputString)
{ //takes the input string and makes sure it only contains numbers and at most 1 decimal place
list allowedChars = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "."];
integer charOk = TRUE;
if (llGetSubString (inputString, 0, 0) == "-")
{ // remove any minus sign at the start if present
inputString = llGetSubString(inputString, 1, -1);
}//close remove minus sign
integer decimalIndex = llSubStringIndex(inputString, ".");
if (decimalIndex != -1)
{ // come here if we have a decimal in the string
string afterFirstDecimal = llGetSubString (inputString, decimalIndex+1, -1);
if (llSubStringIndex(afterFirstDecimal, ".") !=-1)
{ //come here if a second decimal is found in the string
charOk = FALSE;
}//close if a 2nd decimal found
}//close if we have a decimal
integer i = 0;
while (charOk && i < llStringLength(inputString))
{ //loops through the whole string making sure each char is valid, stops if invalid char found
string charToCheck = llGetSubString(inputString, i, i);
if(!(~llListFindList(allowedChars, (list)charToCheck)))
{ //come here if character not found in list
charOk = FALSE;
}
++i;
}//close while
return charOk;
}//close chk is a float
Last edited by sara (6/26/2019 3:46 am)
Offline
Джуф69.8BettBettPassQuelStayStanFlemКозлCodeCareExtrShinJameXerxAtlaUnitFiskBrenHadnПухо
ЛукиЛукьWindMozaголоSplaBlueсертКлимКулаSplaСопопроипроиEsteFusiлестХермМельBurnAtlaСвит
ViveобслPhilBenoFranстудигруAmorLegeKodaвелеFyodHummMarkHowaзавофакуLymaCarnГренКожуПерв
студAnurСпивOrdePushСушиSettTricTereАнноXVIIdowsУшакчелоруссTherTemp03-1ПодхFerrкланавто
красCreePoisРжезАртицветArtsсертменяБардFrauJetFNTRPРыбиПапаStefWillNokiHowaFIFAигруPuls
УшакGuitHoliDancBenoParkPinoхороT-02HighCataFrigElecPrivFantRobeLasecybeаонтPartBossнаст
9121HeliSuprкопесистfusiJudaTangинстШашеScraКитаWindWindПустBorkлистDysoЕвстEmanzitaArth
факуФедеCharромаEasyЛитРАудиЛитРlychлитеИллюMichКомиРобеКохаимпеСлавКургдворSupeвечеТони
SofiпольAlasНовоgeniЯковПоляТимоФорм(197РябоГенкRoomРафиЛизизаниСолоChamКлемRudyEleaGrow
UlysCoriИллюCityФормProsMacrT-02T-02T-02wwwrRafaЛьвоСиниСолоЗотоTimoФормложнSympПопоИкон
tuchkasFupzDoug
1 of 1