TheRookie32
asked on
Changing @Function String Manipulations to Javascript
I have been tasked with coming up with a library of Javascript string manipulations that do the same function as their @formula language relatives...
@left, @right etc...
Any ideas on how to port them over to Javascript? Example of @left?
@left, @right etc...
Any ideas on how to port them over to Javascript? Example of @left?
ASKER
Kinda, i am quite new to Javascript and writing full on functions so can you post an example using it? The idea is to have the @Left function be transferred over to a Javascript function. Meaning it is to accept a stringToSearch, numberOfCharacters and a subString. Not be broken into two different ones...
ASKER
Here is what i have so far, not working quite right yet:
function atLeft(stringToSearch,subS tringOrNum Chars)
{ var pos = -1;
var len = stringToSearch.Length;
if ( isNaN(subStringOrNumChars) )
{ pos = stringToSearch.indexOf(sub StringOrNu mChars);
if ( pos > -1 )
{ return stringToSearch.substring(0 ,pos)
}
else
{
}
}
else
{
}
}
function atLeft(stringToSearch,subS
{ var pos = -1;
var len = stringToSearch.Length;
if ( isNaN(subStringOrNumChars)
{ pos = stringToSearch.indexOf(sub
if ( pos > -1 )
{ return stringToSearch.substring(0
}
else
{
}
}
else
{
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the points!
Interesting challenge you have there, for someone new to javascript! But it'll sure be educational! From what you already had I'm sure you'll do just fine!
Good luck! CU around!
Interesting challenge you have there, for someone new to javascript! But it'll sure be educational! From what you already had I'm sure you'll do just fine!
Good luck! CU around!
ASKER
Yes it has been interesting... I just did an atRight one which was a bit harder... but i got it. And your welcome for the points. :)
At page 8 you'll find "Text" and its methods and properties.
@Left(Txt, Nr) could easily be translated using Txt.substr(start, length)
@Left(Txt, char) would first require calculation of Txt.indexOf(char). Its result could then be fed into substr.
@Explode(Txt, char) would be Txt.split(char), so @Left(Txt,char) could also be written as Txt.split(char)(0).
Does that help?