delimiter

bash: passing paths with spaces as parameters?

我怕爱的太早我们不能终老 提交于 2019-12-03 10:15:14
I have a bash script that recieves a set of files from the user. These files are sometimes under directories with spaces in their names. Unfortunately unlike this question all the filenames are passed via the command line interface. Let's assume the paths are correctly quoted as they are passed in by the user, so spaces (save for quoted spaces) are delimiters between paths. How would I forward these parameters to a subroutine within my bash script in a way that preserves the quoted spaces? #! /bin/bash for fname in "$@"; do process-one-file-at-a-time "$fname" done Note the excessive use of

How to do a while loop with a string redirected into it

人走茶凉 提交于 2019-12-03 09:54:26
Im trying to loop though a string with HTTP links inside and newlines, I want to loop over a line at a time. At the moment I have echo -e "$HTTP_LINKS" | while read HTTP_S_LINK ; do TEST_STRING="test" done But this way I don't have access to the TEST_STRING out side the loop, which is what I want. I'm using the while loop so that it will loop though each newline in $HTTP_LINKS and not just the words in the string. (I don't want to use a for loop with IFS set to \n) I thought maybe I could just do something like this #!/bin/bash while read HTTP_S_LINKS do TEST_STRING="test2" done < $HTTP_LINKS

Backslash zero delimiter '\\0'

人走茶凉 提交于 2019-12-03 01:54:46
I have seen '\0' to be used as a delimiter in mixed binary files (UTF8 strings + binary data). Could anyone explain what '\0' means or point to a good place to study? It's the null character; more info in this Wikipedia article . The two-character \0 representation is used in C source code to represent the NUL character, which is the (single) character with ASCII value 0. The NUL character is used in C style character strings to indicate where the end of the string is. For example, the string "Hello" is encoded as the hex bytes: 48 65 6c 6c 6f 00 In this case, the C compiler automatically adds

How to separate specific elements in string java

你离开我真会死。 提交于 2019-12-02 23:43:17
问题 Example of what I want to do: If you pass in "abc|xyz" as the first argument and "|" as the second argument the method returns List("abc","xyz") public List<String> splitIt(String string, String delimiter){ //create and init arraylist. List<String> list = new ArrayList<String>(); //create and init newString. String newString=""; //add string to arraylist 'list'. list.add(string); //loops through string. for(int i=0;i<string.length();i++){ //stores each character from string in newString.

Java - parsing text using delimiter for separating different arguments

末鹿安然 提交于 2019-12-02 20:15:44
问题 How would you use multiple delimiters or a single delimiter to detect and separate out different string matches? For example, I use a Scanner to parse in the following string: MrsMarple=new Person(); MrsMarple.age=30; I would like to separate out this string to determine, in sequence, when a new person is being created and when their age is being set. I also need to know what the age is being set to. There can be anything between and/or either side of these arguments (there doesn't

How to specify decimal delimiter

[亡魂溺海] 提交于 2019-12-02 15:23:36
问题 I have a fairly simple problem. I am getting real-number input like 6.03 , but that gives me errors. If I change it to 6,03 , it's ok. I, however, can't change the input I need to process, so how do I tell Java to use . as the delimiter instead of , ? Scanner sc = new Scanner(System.in); double gX = sc.nextDouble(); // Getting errors Thanks 回答1: Scanner can be provided with Locale to use, you need to specify Locale that uses . as decimal separator: Scanner sc = new Scanner(System.in)

How to parse a file with special delimiters in a batch file?

為{幸葍}努か 提交于 2019-12-02 12:22:51
I want to parse a file that looks like this using batch : a: string_containing_various_characters,.:and spaces/1 b: string_containing_various_characters,.:and spaces/2 c: string_containing_various_characters,.:and spaces/3 d: string_containing_various_characters,.:and spaces/4 e: string_containing_various_characters,.:and spaces/5 f: string_containing_various_characters,.:and spaces/6 g: string_containing_various_characters,.:and spaces/7 I need to extract every string following "a: ","b: ","c: " etc... I can't use space as a delimiter since there can be spaces in the strings. The only thing

Delimiter tens and units in c++ literals

半世苍凉 提交于 2019-12-02 11:37:22
问题 In Java I can do: int i = 1_200_200; How can I do something the same in c++? I mean what should I use instead of an underscore? 回答1: Since C++14 you can use single quotes (') for integer literal to improve the readability, e.g. int i = 1'200'200; Optional single quotes(') may be inserted between the digits as a separator. They are ignored by the compiler. 回答2: In C++ you can use the ordinary quote. For example #include <iostream> int main() { int x = 1'234'567; std::cout << "x = " << x << std

Java Scanner Delimiter Usage

自古美人都是妖i 提交于 2019-12-02 10:15:48
I'd like to specify a delimiter for a scanner that splits on some pattern, but doesn't remove that pattern from the tokens. I can't seem to make this work, as anything that is identified by the regex also gets eaten as part of the delimiter. Any suggestions? My specific problem, I have file that looks like: text/numbers mix numbers numbers text/numbers mix numbers numbers numbers . . I'd like to split out from the text/numbers mix+rows until the next text/numbers mix. I have the regex to identify them, but as stated, using that as the delimiter eats part of what I want. EDIT: code addition:

How to separate specific elements in string java

早过忘川 提交于 2019-12-02 08:55:01
Example of what I want to do: If you pass in "abc|xyz" as the first argument and "|" as the second argument the method returns List("abc","xyz") public List<String> splitIt(String string, String delimiter){ //create and init arraylist. List<String> list = new ArrayList<String>(); //create and init newString. String newString=""; //add string to arraylist 'list'. list.add(string); //loops through string. for(int i=0;i<string.length();i++){ //stores each character from string in newString. newString += string.charAt(i); } newString.replace(delimiter, ""); //remove string from arraylist 'list'.