-2

I have a string like this '\IonSubsystem1TRAN-88252' and I want to convert it to string like this: '\IonSubsystem1\TRAN-88252'.

How do I add the backslashes in the right spots in a generic way?

Brk
  • 1,247
  • 2
  • 23
  • 55

2 Answers2

1

For this example the easiest way would be to use the .replace function.

newString = string.replace('IonSubsystem1', 'IonSubsystem1\\');

Keep in mind that you need \\ since a single Backslash is interpreted as a escape character.

Colin Rauch
  • 515
  • 1
  • 6
  • 17
0

The simplest way I'd do it is by making the substring of the given string using javascript's substring method and appending an additional "/" after it.That is storing the acquired substr in a variable and + "/" after it.But again it depends how generic you want it to be.

Technologeek
  • 190
  • 1
  • 2
  • 13