[Solved] How to split a string if any chracter is found in java

You can use String‘s methods replaceAll and split together here. String one = “show ip interface brief | include 1234**\n Gi1/23.1234 xxx.225.xxx.106 YES manual up up”; String[] tokens = one.replaceAll(“[^\\n]+\\n\\s*”, “”).split(“\\s+”); System.out.println(Arrays.toString(tokens)); Output [Gi1/23.1234, xxx.225.xxx.106, YES, manual, up, up] solved How to split a string if any chracter is found in java

[Solved] tokenizing and parsing with python

To retrieve the data from the file.txt: data = {} with open(‘file.txt’, ‘r’) as f: # opens the file for line in f: # reads line by line key, value = line.split(‘ : ‘) # retrieves the key and the value data[key.lower()] = value.rstrip() # key to lower case and removes end-of-line ‘\n’ Then, data[‘name’] … Read more

[Solved] How to store each word from a scanner to an array

If I understand your question correctly, this is that I would do Scanner keyb = new Scanner(System.in); System.out.print(“Enter a sentence: “); String input = keyb.nextLine(); String[] stringArray = input.split(“,”); To see the results: for(int i=0; i < stringArray.length; i++){ System.out.println(i + “: ” + stringArray[i]); } This will work for any size sentence as long … Read more