I have to drop out the first line (UNA:+.? ') from the following input string:
UNA:+.? '
UNB+UNOA:2+422207530:9+8713381197918:14+20141212:1555+1082746344'
UNH+1+ORDERS:D:97A:UN'
BGM+220+105961-44+9'
DTM+137:20140121:102'
NAD+BY+0048003479::91'
NAD+SE+0000805406::91'
NAD+DP+0048003479::91'
CUX+2:USD+9'
PIA+1+M1PL05883LOT:BP::92'
PIA+1+927700077001:VP::91'
PRI+AAA:9:::1:PCE'
SCC+1'
QTY+21:10000:PCE'
DTM+2:11022014:102'
PIA+1+M1PL05883LOT:BP::92'
PIA+1+927700080201:VP::91'
PRI+AAA:9:::1:PCE'
SCC+1'
QTY+21:20000:PCE'
DTM+2:04022014:102'
UNS+S'
UNT++1'
UNZ+1+10596144'
#Jerry has the right answer...
Assuming your string is in a variable input, you can do:
String output = input.split('\n') // Split into an array based on newline
.drop(1) // Drop the first element
.join('\n') // Join back into a string separated by newline
Related
I have this arrayList that receives data dynamically from a database
val deviceNameList = arrayListOf<String>()
Getting the index 0 of the arraylist ie deviceNameList[0] prints a string of such a format:
[Peter, James]
How can i list all names in deviceNameList[0] individually.
Assuming your input string is [Peter, James], you could try removing the square brackets at both ends, then regex splitting on comma followed by optional whitespace.
String input = "[Peter, James]";
String[] names = input.substring(1, input.length()-1).split(",\\s*");
System.out.println(Arrays.toString(names));
This prints:
[Peter, James]
Note that Java itself places square brackets around the array contents in Arrays.toString. They are not part of the actual data.
I had to split string data based on Comma.
This is the excel data:-
Please find the excel data
string strCurrentLine="\"Himalayan Salt Body Scrub with Lychee Essential Oil from Majestic Pure, All Natural Scrub to Exfoliate & Moisturize Skin, 12 oz\",SKU_27,\"Tombow Dual Brush Pen Art Markers, Portrait, 6-Pack\",SKU_27,My Shopify Store 1,Valid,NonInventory".
Regex CSVParser = new Regex(",(?=(?:[^\"]\"[^\"]\")(?![^\"]\"))");
string[] lstColumnValues = CSVParser.Split(strCurrentLine);
I have attached the image.The problem is I used the Regex to split the string with comma but i need the ouptut just like SKU_27 because string[0] and string2 contains the forward and backward slash.I need the output string1 and remove the forward and backward slash.
The file seems to be a CVA file. For CVA to be properly formatted, it will use quotes "" to wrap strings that contains comma, such as
id, name, date
1,"Some text, that includes comma", 2020/01/01
Simply split the string by comma, you will get the 2nd column with double quote.
I'm not sure whether you are asking how to remove the double-quotes from lstColumnValues[0] and lstColumnValues[2], or add them to lstColumnValues[1].
To remove the double-quotes, just use Replace:
string myString = lstColumnValues[0].Replace("\"", "");
If you need to add them:
string myString = $"\"{lstColumnValues[1]}\"";
Trying to use rstrip() at its most basic level, but it does not seem to have any effect at all.
For example:
string1='text&moretext'
string2=string1.rstrip('&')
print(string2)
Desired Result:
text
Actual Result:
text&moretext
Using Python 3, PyScripter
What am I missing?
someString.rstrip(c) removes all occurences of c at the end of the string. Thus, for example
'text&&&&'.rstrip('&') = 'text'
Perhaps you want
'&'.join(string1.split('&')[:-1])
This splits the string on the delimiter "&" into a list of strings, removes the last one, and joins them again, using the delimiter "&". Thus, for example
'&'.join('Hello&World'.split('&')[:-1]) = 'Hello'
'&'.join('Hello&Python&World'.split('&')[:-1]) = 'Hello&Python'
I want to parse a txt file with information.
That i want is, to find all numbers in that string
I mean that i want a sub to return the first number (as many digits as is the number ) after the second one , the third one etc.
Is it possible?
$string = preg_replace('/\D/', ' ', $string);
$numberArray = explode(' ',$string);
I have a file with chinese content that I need to parse. Each post has some weird delimitter between fields and I am trying to isolate the fields but cannot recognize the delimitter.
Dim stringSplitter() as string = {" "}
Try
sampleResults = entry.Split(stringSplitter,StringSplitOptions.RemoveEmptyEntries)
.....
A sample of the post content;
108087006686338t.qq.com/GAOCHUANG8899homeGAOCHUANG8899homehttp://t.qq.com/p/t/1080870066863382012-03-22 04:49:46
The separator starts after the first set of digits 108087006686338 DELIMITTER t.qq.com/GAOCHUANG8899home . I initially thought I could split it using json but this is definitely not json format.
Sorry when I post the original the delimitters disappear when making this post. The delimitter looks like a rectangular block
EDIT:
Ok using the hex editor I identified the character hex value as 01 and it looks like a period but the period has a value of 2E. Does this mean anything to anyone?
EDIT:
Reproducing the question: can I split a string based on a hex value. If the value is "01" then how would I split the string based on that value.
EDIT:
final answer:`
Dim hvalue as Char = Char(1)
Dim stringSplitter() as string = {hvalue}
Let's say you have input $input and delimitter with ascii code of 01.
Perl:
my $input = ...
my #output = split(chr(01), $input);
print "$_\t" for #output; # print all items
The code above will split your $input into #output array, so then you can access items via
$output[0] # first item
$output[1] # second item
...
$#output + 1 # number of items
Visual-Studio-2010:
Dim hvalue as Char = Char(1)
Dim stringSplitter() as string = {hvalue}