I have a variable i.e, "Classification" and it`s value is "Vol 4" and I needs to replace white space with "+" character in "Classification" variable. So, I required to write a script in bean shell to replace white space character by character.
Can anyone help me in this ?
解决方案
I think that you're looking for URL encoding function. There are 2 ways to go:
Easy one - use JMeter's function to encode the URL. Assuming that you have "Classification" variable it'll be something like ${__urlencode(${Classification})}
Harder (but more flexible) one - use Beanshell to do the same.
Example Beanshell code:
import java.net.URLEncoder; // import required class
String classification = vars.get("Classification").toString(); // obtain value of "Classification" variable
String encoded = URLEncoder.encode(classification, System.getProperty("file.encoding")); // encode "Classification variable and save result to "encoded" string
vars.put("Classificatoin",encoded); // replace "Classification" variable with new value
If you need just replacing single or multiple characters - see the solution is in previous answer.
References:
__urlEncode() JMeter Function
String Java class documentation