How do I replace forward slashes (/) with backwards slashes (\)

Katalon Studio, Version: 6.2.0, Build: 1
Windows 7

Hi Folks,
I am using RunConfiguration.getProjectDir() to set my relative file upload path as follows.
In my case, I need to change forward slashes (/) to backwards slashes () so I am doing the following.
Please see my Actual and Expected. Can someone see where I am going wrong?

Import file:

import com.kms.katalon.core.configuration.RunConfiguration
String Path = RunConfiguration.getProjectDir() + '/Data Files/TestLicense.jpg';
Path = Path.replace('///', '/\\'); 
println("Path: " + Path);
SLF4J: The requested version 1.7.16 by your slf4j binding is not compatible with [1.6]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
2019-07-18 11:37:35.904 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2019-07-18 11:37:35.914 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/0 HOW_TO_CASES/25 sample
2019-07-18 11:37:36.022 DEBUG c.k.katalon.core.main.TestCaseExecutor   - Evaluating variables for test case
2019-07-18 11:37:36.103 DEBUG testcase.25 sample                       - 1: Path = getProjectDir() + "/Data Files/TestLicense.jpg"
2019-07-18 11:37:36.105 DEBUG testcase.25 sample                       - 2: println("Path: " + Path)
Path: C:/Users/devers/Katalon_Example_Projects/Katalon-Test-Project/Data Files/TestLicense.jpg
2019-07-18 11:37:36.125 TRACE c.k.katalon.core.main.TestCaseExecutor   - END null: println("Path: " + Path)
2019-07-18 11:37:36.125 DEBUG c.k.katalon.core.main.TestCaseExecutor   - ✓ Test Cases/0 HOW_TO_CASES/25 sample
2019-07-18 11:37:36.125 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/0 HOW_TO_CASES/25 sample

Actual path

Path: C:/Users/devers/Katalon_Example_Projects/Katalon-Test-Project/Data Files/TestLicense.jpg

Expected (needed) path

Path: C:\Users\devers\Katalon_Example_Projects\Katalon-Test-Project\Data Files\TestLicense.jpg
String s = "/russ/thomas/"
	
s = s.replace(/\//, '\\') // ==> \russ\thomas\
2 Likes

Or without regex, you can do this:

s.replaceAll(“/“, “\\”)

3 Likes

Both of these work for me.

Really appreciate the quick response and solutions.

Thanks!

3 Likes