How to split String with "\" as a delimiter? and also how to replace "\" into ":"?

AuroraBlaze

Hi I would like to know what should I put in order to split the string into parts using "\" as a delimiter?

The String returned by the server will be as shown below

String test ="\\ipAddress\FolderA\InnerFolderA\abc.mp4"; << this one give me error ,thus i have to put in another "\",

String test ="\\ipAddress\\FolderA\\InnerFolderA\\abc.mp4";

String parts[] = test.split("\\");
        String part0 = parts[0];
        String part1 = parts[1];
        String part2 = parts[2];

and when I run it, it gives me error:

Exception in thread "main" java.util.regex.PatternSyntaxException: Unexpected internal error near index 1.

Also when I tried replacing the String using this line of code to replace the "\" as in

String output = test.replaceAll("\\", ":");

it also give me error .

Ankur Singhal
 public static void main(String[] args) {

        String test = "\\ipAddress\\FolderA\\InnerFolderA\\abc.mp4";
        String output = test.replaceAll("\\\\", ":");
        System.out.println(output);

        String parts[] = test.split("\\\\");
        String part0 = parts[0];
        String part1 = parts[1];
        String part2 = parts[2];
        System.out.println(part0);
        System.out.println(part1);
        System.out.println(part2);

    }

output

:ipAddress:FolderA:InnerFolderA:abc.mp4

ipAddress
FolderA

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Java: how to split a string when you want a delimiter of nothing

分類Dev

split string last delimiter

分類Dev

How to properly split on a non escaped delimiter?

分類Dev

How to split delimiter array values into another Array

分類Dev

How to split and iterate substrings by delimiter in BOURNE SHELL?

分類Dev

How to use Multiple Delimiter in preg_split()

分類Dev

How do I split a string with several delimiters, but only once on each delimiter? Python

分類Dev

How to split a string with Java regex including a variable-width delimiter in the resulting list

分類Dev

Split python string with multiple delimiter

分類Dev

How to Tokenize String with Commas and Line Delimiter

分類Dev

How to explode a string without proper delimiter - PHP

分類Dev

How to split String with ||

分類Dev

How to split the string

分類Dev

How to split the following string

分類Dev

How to split a [String] into rows?

分類Dev

How do I split column values into new rows at delimiter

分類Dev

How to replace ™ in a string?

分類Dev

R: Fast string split on first delimiter occurence

分類Dev

Split string into array without deleting delimiter?

分類Dev

Split string by repeatable delimiter in Java/Kotlin

分類Dev

split string only by the first occurrence of a delimiter

分類Dev

How to split the string into 2 with python?

分類Dev

How to Split String, and Include splitter?

分類Dev

How to split a string into multiple columns?

分類Dev

How to split string and display it in a gridview ?

分類Dev

How to split string by specific keywords?

分類Dev

How to split text string to parts?

分類Dev

How to replace string in "%" in make file

分類Dev

How to replace string and upload with php

Related 関連記事

ホットタグ

アーカイブ