Javafx clipboard double newlines - javafx-2

I'm fairly sure this is a bug in the JavaFX clipboard but I want to make sure I'm not doing something stupid. I'm programatically placing plain text on to the clipboard using the following code:
Clipboard clipboard = Clipboard.getSystemClipboard();
ClipboardContent content = new ClipboardContent();
//String test = "1" + System.lineSeparator() + "2"; //Example 1 - Two lines
//String test = "1\r\n2"; //Example 2 - Two lines
String test = "1\n2"; //Example 3 - One line
content.putString(test);
clipboard.setContent(content);
Example 1 and 2 result in this text after pasting
1
2
Example 3 results in this text after pasting (as expected)
1
2
Making notepad++ show line ends confirms that in the first two example the lines endings are being doubled. Running a debugger over it shows the String is fine after it's been placed into the ClipboardContent but I stopped following it after that.
This is all on Windows 8 (the running code and the paste operation). My conclusion is that somewhere deep in the system it's detecting the need for windows line endings and converting each of the \r and \n into \r\n just before the paste happens.

I resolved this issue with a simple replaceAll like this:
final ClipboardContent content = new ClipboardContent();
content.putString(str.replaceAll("\r\n", "\n"));

Related

Batch Bookmark & Extraction of Bookmarked lines into MULTIPLE new file in EmEditor

I will like to do a follow up question to this question here : How to search and bookmark multiple strings at once in emeditor?
However, #Yutaka gave this response: https://i.stack.imgur.com/HLYoo.png and that is my follow up question.
How can each bookmarked strings saved differently or opened differently in emeditor when use the "extract bookmark lines to new file".
I will appreciate your response.
I am expecting the result of each bookmark strings to open in different files in em editor.
Batch Extract
The Batch Extract button in the Batch Find dialog will output all matched lines to a file, with labels indicating the entry that the lines matched with.
Example output:
===== a =====
a
apple
===== b =====
b
Macro
This macro finds the given array of strings with the extract option, and it saves each result to separate files. Make sure to change the marked lines.
var filePath = document.FullName;
var strings = ["a", "b", "e"]; // Change these
for (var i = 0; i < strings.length; i++) {
editor.OpenFile(filePath);
document.selection.Find(strings[i], eeFindSelectAll | eeFindExtract, 0);
document.Save("%HOMEPATH%\\Downloads\\" + strings[i] + ".txt"); // Change path
}
I tested it on this file. Make sure to save it before running the macro.
a
b
c
d
apple

Split function in Excel VBA returning odd characters

I have a text file containing danish characters
"Næsby IF afdeling * Badminton * Sport *"
When splitting and placing them in an array the danish characters gets "messed up"
This is the complete Text string in a *.TXT file to be split up in Excel columns:
"Ulrich*wiingreen*BenPauWin05 Aps*Søballehøjen 12*5270*Odense N*+4530212215*ulrich#wiingreen.eu*Næsby IF afdeling*Badminton*Sport* *Hal 1*Hal 2*99*11/03/2022 13:00*11/03/2022 17:00*kkkk"
The code doing this is:
If InStr(FileName, "forespoerg_") <> 0 Then
OrderArr = Split(OrderDetails, "*")
OrderRow = OrdersDB.Range("A99999").End(xlUp).Row + 1
OrdersDB.Cells(OrderRow, 1).Value = Application.WorksheetFunction.Max(Range("A4:A9999")) + 1
OrdersDB.Cells(OrderRow, 2).Value = Date
For OrderCol = 3 To 20
OrdersDB.Cells(OrderRow, OrderCol).Value = OrderArr(OrderCol - 3)
Next OrderCol
End If
The splitting works just fine. Unfortiunately the characters gets messed up.
Example: "Søballehøjen 12" imports as: "Søballehøjen 12"
Can anyone give a hint to solve this character issue.
Not sure but I suspect encoding mismatch. You can try opening your text file with VS Code and watch at the bottom right what is its encoding.
You can then use StrConv(yourTextVar, someconversion) wher someconversion is a value like vbUnicode or vbFromUnicode (see options here)
How do you import the text file ? If your file is a unix or another non Windows flavour you could try reading the file using an ADODB.Stream, which offers fine control on the encoding. I quickly found a sample here.

printing txt file from VBA for Matlab

I am working parallel with Excel and VBA in order to create txt files I wish to use for MATLAB. However, I experience some format issues I can't resolve.
For instance, the following VBA
Open "example.txt" For Output As #1
For i = 1 To 5
Print #1, Sheets("Example").Cells(i + 3, 3)
Next i
Indeed prints numbers (reals) it is supposed to however MATLAB struggles with reading this example .txt file.
There are some characters VBA is printing. I don't know how to delete those within a VBA code.
Example.txt opened in matlab. Note the NaN read by MATLAB from a text file:
VBA text file - Note a line as the first element of a column
Perhaps there is a character that is invisible.
A possible solution is to remove those characters with regex.
Add reference to Microsoft VBScript Regular Expression 5.5
Then the following VBA code:
Set re = New RegExp
re.Pattern = "[^0-9]"
Open "example.txt" For Output As #1
For i = 1 To 5
Print #1, re.Replace(Sheets("Example").Cells(i + 3, 3).value, vbNullString)
Next i
This should remove anything that is not a digit from the cell before printing it to the text document.

My requirement is to develop an application in power builder, which receives Scanned barcodes and decodes it

My requirement is to develop an application in power builder, which receives Scanned barcodes and decodes it
The application should also be able to reveal hidden ASCII codes in the scanned barcodes.
Like:-
ASCII Codes
TAB - 9
BS Backspace - 8
EOT End of Transmission - 4
FF Form Feed - 12
Etc.
When scanned codes arrives at datawindow, rich text input, single line edit it comes as one character at a time
So my logic would be is to take that character before it is written in Datawindow or rich text input and find its ascii value and if it is less the 32 (which means it is a hidden character)
I can give brackets around it and show in display screen. so that hidden characters are not missed out.
Eg Scanned code abcdefgh
Decoded code will be abc[09]def[12]gh
So I tried with EditChanged, itemchanged , KeyDown events but I am unable to get the character before it is written in datawindow. Because once it is been written in datawindow hidden characters will be missed out.
Is there any event in powerbuilder will give me the scannedcode after it has been scanned but before it has been written in data window or rich text control,
Something like PreviewTextInput Event, which will preview the text before writing it into the data window.
Sample barcode Image uploaded
Thanks and regards,
The Event ID pbm_dwnchanging might work for you. Try creating an event on the DataWindow control that uses pbm_dwnchanging - this appears to capture the characters as they're being entered, but before they're put into the edit control (like you would think pbm_dwnkey should).
// "prototype" in the window object's datawindow control declaration:
event onpbmdwnchanging pbm_dwnchanging
Here is the pbm_dwnchanging event extension's code - basically, it calls a method that builds the "representation" of the data being entered and logs it (i.e.: appends a Multi-line Edit control in the window).
event onpbmdwnchanging;
string dataRepresentation
// get the representation of the data
dataRepresentation = getDataRepresentation(data)
// log it to the window's MLE
addLogMessage("onpbmdwnchanging - row: " + string(row) + " data: '" +
dataRepresentation + "'")
return
end event
Lastly, the function that builds the "representation" of the data:
protected function string getDataRepresentation (string as_input);
string dataRep
char dataChars[]
string currentChar
long ll_datalength, ll_index
dataChars = as_input // cast the string into a character array
ll_datalength = upperbound(dataChars)
for ll_index = 1 to ll_datalength
currentChar = dataChars[ll_index]
if Asc(currentChar) < 32 then
// "hidden" character
dataRep += "[" + string(Asc(currentChar)) + "]"
else
dataRep += string(currentChar)
end if
next
return dataRep
end function
note: tested and works in PB 12.6

Adding a newline character within a cell (CSV)

I would like to import product descriptions that need to be logically broken according by things like description, dimensions, finishes etc. How can I insert a line break so that when I import the file they will show up?
This question was answered well at Can you encode CR/LF in into CSV files?.
Consider also reverse engineering multiple lines in Excel. To embed a newline in an Excel cell, press Alt+Enter. Then save the file as a .csv. You'll see that the double-quotes start on one line and each new line in the file is considered an embedded newline in the cell.
I struggled with this as well but heres the solution. If you add " before and at the end of the csv string you are trying to display, it will consolidate them into 1 cell while honoring new line.
csvString += "\""+"Date Generated: \n" ;
csvString += "Doctor: " + "\n"+"\"" + "\n";
I have the same issue, when I try to export the content of email to csv and still keep it break line when importing to excel.
I export the conent as this: ="Line 1"&CHAR(10)&"Line 2"
When I import it to excel(google), excel understand it as string. It still not break new line.
We need to trigger excel to treat it as formula by:
Format -> Number | Scientific.
This is not the good way but it resolve my issue.
supposing you have a text variable containing:
const text = 'wonderful text with \n newline'
the newline in the csv file is correctly interpreted having enclosed the string with double quotes and spaces
'" ' + text + ' "'
On Excel for Mac 2011, the newline had to be a \r instead of an \n
So
"\"first line\rsecond line\""
would show up as a cell with 2 lines
I was concatenating the variable and adding multiple items in same row. so below code work for me. "\n" new line code is mandatory to add first and last of each line if you will add it on last only it will append last 1-2 character to new lines.
$itemCode = '';
foreach($returnData['repairdetail'] as $checkkey=>$repairDetailData){
if($checkkey >0){
$itemCode .= "\n".trim(#$repairDetailData['ItemMaster']->Item_Code)."\n";
}else{
$itemCode .= "\n".trim(#$repairDetailData['ItemMaster']->Item_Code)."\n";
}
$repairDetaile[]= array(
$itemCode,
)
}
// pass all array to here
foreach ($repairDetaile as $csvData) {
fputcsv($csv_file,$csvData,',','"');
}
fclose($csv_file);
I converted a pandas DataFrame to a csv string using DataFrame.to_csv() and then I looked at the results. It included \r\n as the end of line character(s). I suggest inserting these into your csv string as your row separation.
Depending on the tools used to generate the csv string you may need escape the \ character (\r\n).

Resources