reverseSlash method

String? reverseSlash(
  1. int direction
)

Reverses slash in the String, by providing direction,

0 = / -> \\

1 = \\-> /

Example

String foo1 = 'C:/Documents/user/test';
String revFoo1 = foo1.reverseSlash(0); // returns 'C:\Documents\user\test'

String foo2 = 'C:\\Documents\\user\\test';
String revFoo2 = foo1.reverseSlash(1); // returns 'C:/Documents/user/test'

Implementation

String? reverseSlash(int direction) {
  if (this.isBlank) {
    return this;
  }

  switch (direction) {
    case 0:
      return this!.replaceAll('/', '\\');
    case 1:
      return this!.replaceAll('\\', '/');
    default:
      return this;
  }
}