Jump to content

Recommended Posts

Posted

Hi All,

 

Ho can I trim a string so that all characters after a specific value are dropped. E.g I want to DROP the "~1.xls" from the following string. 0000715 RECORDATI PHARMACEUTICALS LTD 07 2010~1.xls. So I want the code to lookup "2010" in the string and delete all charaters after that.

 

Thanks

 

T

Posted

I forget the exact JavaScript phrasing, but just do a string find to locate the starting position of the phrase "2010", and then use a trim operation to chop off everything from that point (plus or minus however many characters you need to shift by). It takes a bit of trial and error with the +-, but it's pretty straightforward logic.

 

Mercifully it's a few years since I had to type out some JS though, so can't give you the code directly.

Posted

Thanks All.. am not sure what the syntax should be. Please have a look at my code below. Its the variable "clpApprovedData" that I need to apply this trim on.

 

 

function IncorrectAttachment()

{

var actionName = eworkGetField("txtActionName");

var strorginal = eworkGetField("clpGeneratedData");

var strreturned = eworkGetField("clpApprovedData");

 

if(strorginal.toUpperCase()!= strreturned.toUpperCase())

{

alert("strorginal=" + strorginal + "strreturned=" + strreturned);

return false;

}

return true;

}

Posted

I presume you mean strreturned? As that's a variable containing the string I presume eworkGetField returns.

 

Try:

var strreturned = eworkGetField("clpApprovedData");

strreturned =  strreturned.substring(0,  strreturned.lastIndexOf('~'));

if(strorginal.toUpperCase()!= strreturned.toUpperCase())

 

Which is what webman suggested, inserted into your code.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...