An error occurred while writing the data to a file: Dangling meta character '+' near index 0 + ^

Hi Support,

I haven't seen this one before and was not able to fix it myself. The token is as follows:

streetaddress=+~@ADDRESS@~&citystatezip=~@CITY@~%2C+~@STATE@~+~@ZIP@~'

The ADDRESS and CITY has + (plus sign) in the HTML, such as:

425+N+Curson+Ave

and

Los+Angeles

so I applied the following script:

String [] variables = {"ADDRESS","CITY"};

i = 0;

// Iterate through each variable in the array above
while (i < variables.length){
    //Get the variables to be fixed
    value = session.getVariable(variables[i]);

    //Log the UNFIXED values
    session.log("UNFIXED: " + variables[i] + " = " + value);

    if(value != null){
        //Remove non-numerical elements<
        value = value.replaceAll("+", " ");

        // Set variables with new values
        dataRecord.put(variables[i], value);
        session.setVariable(variables[i], value);

        //Log the FIXED values
        session.log("FIXED " + variables[i] + " = " + session.getVariable(variables[i]));
     }
     i++;
}

the log is as follows:

Writing data to a file.
UNFIXED: ADDRESS = 425+N+Curson+Ave
FIXED ADDRESS = 425+N+Curson+Ave
UNFIXED: CITY = Los+Angeles
FIXED CITY = Los+Angeles

and the following error message:

UNFIXED: ADDRESS = 425+N+Curson+Ave
An error occurred while writing the data to a file: Dangling meta character '+' near index 0 + ^

Thanks for your help,

Adrian

Thanks...

That did the trick. Thanks again!

The replaceAll takes a RegEx,

The replaceAll takes a RegEx, and the "+" is a special character. You might just need to escape the plus with a backslash, or you could use URLDecode.

How do I...

Hi Jason,

How do I escape the plus with a backslash? I tried:


"\+"

but it did not recognize the backslash.

I looked at the link URLDecode and was a little confused of how to apply it. It said the plus sign "+" is converted into a space character " ". So I replaced the "+" with " " but it did not remove the +.

Thanks,

Adrian

Try this import

Try this

import java.net.URLDecoder;

/* Testing
session.setVariable("ADDRESS", "Tooth+fairy");
//*/

String [] variables = {"ADDRESS","CITY"};

i = 0;

// Iterate through each variable in the array above
while (i < variables.length)
{

//Get the variables to be fixed
value = session.getVariable(variables[i]);

//Log the UNFIXED values
session.log("UNFIXED: " + variables[i] + " = " + value);

if(value != null)
{
//Remove non-numerical elements
String value = URLDecoder.decode(value, "UTF-8");

// Set variables with new values
dataRecord.put(variables[i], value);
session.setVariable(variables[i], value);

//Log the FIXED values
session.log("FIXED " + variables[i] + " = " + session.getVariable(variables[i]));
}
i++;
}

Thanks...

That did the trick. Thanks again!