How can i check a Line contains a special chracter?

BenMansourNizar

Hi I have a file stored in Linux system that contains a special character ^C Something like this:

ABCDEF^CIJKLMN Now i need to read this file in java and detect that there is this ^C to make split. The problem that to read the file in UNIX.I must use cat -v fileName to see the special chracter ^C elsewhere i can't see it. This is my sample code.

    InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(this),
            Charset.forName("UTF-8"));

    BufferedReader br = new BufferedReader(inputStreamReader);
    String line;
    while ((line = br.readLine()) != null) {
        if (line.contains("^C")) {
            String[] split = line.split("\\" + sepRecord);
            System.out.println(split);

    }
Laf

You are checking if the line contains the String "^C", not the character '^C' (which corresponds to 0x03, or \u0003). You should search for the character 0x03 instead. Here's a code example that would work in your case:

byte[] fileContent = new byte[] {'A', 0x03, 'B'};
String fileContentStr = new String (fileContent);
System.out.println (fileContentStr.contains ("^C")); // false
System.out.println (fileContentStr.contains (String.valueOf ((char) 0x03))); // true
System.out.println (fileContentStr.contains ("\u0003")); // true, thanks to @Thomas Fritsch for the precision

String[] split = fileContentStr.split ("\u0003");
System.out.println (split.length); // 2
System.out.println (split[0]); // A
System.out.println (split[1]); // B

The ^C character is displayed in Caret Notation, and must be interpreted as a single character.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I check if a string contains only a particular set of special characters in Javascript?

From Dev

How can I check (and delete) if the last line (that contains the last occurence of a string) has a comma as last character?

From Dev

How can I check if a line contains specific string from a list of strings?

From Dev

How can i check if $varA contains $varB?

From Dev

How can I check if a dictionary contains a dictionary?

From Dev

how can I read line by line insert into an array with special condition?

From Dev

how can I sort the line of a file according to the special part of the line

From Dev

How to check if a string contains a special character (!@#$%^&*()_+)

From Dev

How to check if a double value contains special characters

From Dev

How to check if a string contains special characters?

From Dev

How can I check if the cursor is at the end of a line?

From Dev

How can I check minlength and restrict special characters with Vue Js?

From Dev

How can I check if the user input is a word and not a special character like (*!?)?

From Dev

Pandas: How can I check if a pandas dataframe contains a specific value?

From Dev

In R, how can I check whether a list contains a particular key?

From Dev

How can I check if a file contains a string or a variable in JavaScript?

From Dev

Bitwise - How can I check if a binary number contains another?

From Dev

How can I check if an ArrayList contains any element of another ArrayList?

From Dev

How can I check if a string contains Chinese in Swift?

From Dev

How can I check if a QString contains only "invisible" characters?

From Dev

How can I check if a cell in Excel spreadsheet contains number

From Dev

How can I check if a HashSet contains an item using the hash of the item?

From Dev

How can I check If a nested array contains a value?

From Dev

How can I check if a string contains letters in Swift?

From Dev

Javascript: How can i check if a array contains certain values

From Dev

How can I check if textarea (tinymce) only contains space?

From Dev

How can I check if the string contains certain word?

From Dev

How can I check if javascript array already contains a specific array

From Dev

How can I check if a string contains an hexadecimal value in VBScript?

Related Related

  1. 1

    How can I check if a string contains only a particular set of special characters in Javascript?

  2. 2

    How can I check (and delete) if the last line (that contains the last occurence of a string) has a comma as last character?

  3. 3

    How can I check if a line contains specific string from a list of strings?

  4. 4

    How can i check if $varA contains $varB?

  5. 5

    How can I check if a dictionary contains a dictionary?

  6. 6

    how can I read line by line insert into an array with special condition?

  7. 7

    how can I sort the line of a file according to the special part of the line

  8. 8

    How to check if a string contains a special character (!@#$%^&*()_+)

  9. 9

    How to check if a double value contains special characters

  10. 10

    How to check if a string contains special characters?

  11. 11

    How can I check if the cursor is at the end of a line?

  12. 12

    How can I check minlength and restrict special characters with Vue Js?

  13. 13

    How can I check if the user input is a word and not a special character like (*!?)?

  14. 14

    Pandas: How can I check if a pandas dataframe contains a specific value?

  15. 15

    In R, how can I check whether a list contains a particular key?

  16. 16

    How can I check if a file contains a string or a variable in JavaScript?

  17. 17

    Bitwise - How can I check if a binary number contains another?

  18. 18

    How can I check if an ArrayList contains any element of another ArrayList?

  19. 19

    How can I check if a string contains Chinese in Swift?

  20. 20

    How can I check if a QString contains only "invisible" characters?

  21. 21

    How can I check if a cell in Excel spreadsheet contains number

  22. 22

    How can I check if a HashSet contains an item using the hash of the item?

  23. 23

    How can I check If a nested array contains a value?

  24. 24

    How can I check if a string contains letters in Swift?

  25. 25

    Javascript: How can i check if a array contains certain values

  26. 26

    How can I check if textarea (tinymce) only contains space?

  27. 27

    How can I check if the string contains certain word?

  28. 28

    How can I check if javascript array already contains a specific array

  29. 29

    How can I check if a string contains an hexadecimal value in VBScript?

HotTag

Archive