Bind breakline symbol to Label.Text - string

When binding a Label.Text
have tried many ways:
\n \r
but none of them are being displayed as breakline
I refuse to believe I will need to dynamically create a Custom control to generate spans on numbers of breakline symbol...
is there any easier/simpler approach ?
What I've tried:
string BreaklineText = "Text first line\nText second line"
string BreaklineText = "Text first line\rText second line"
string BreaklineText = #"Text first line
Text second line"
string BreaklineText = #"Text first line
Text second line"
The xaml:
<Label Text="{Binding BreaklineText}"/>
It should be displayed on my view as
Text first line
Text second line

It's not the optimal solution since I wanted to find a symbol that could be interpreted as BreakLine on XAML, but it will do the job.
string BreaklineText = "Text first line\nText second line".Replace("\n", System.Environment.NewLine);

using Ascii equivalent
in XAML should work, you have missed ;
<Label Text="Text first line
Text second line"/>

I built on #Motumbo and set System.Environment.NewLine to a variable like
var nl = System.Environment.NewLine;
then I could write variations on:
string text = "some text" + nl + "text on newline";
Also found that "\r\n" works on Droid and UWP. Did not have iOS to test. So:
string text = "some text\r\ntext on newline";
worked for me.

Related

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.

Excel Escape 2 ""

& CHAR(10) & REPT(" ", 20)& "5. Change object BusinessCardRequest(FirstName=$CreatedFor/FirstName;LastName=$CreatedFor/Surname;EmailAddress=$CreatedFor/Email;MobileNumber=$CreatedFor/Mobile;PositionTitle=if $PositionFirst != empty then $PositionFirst/Title else "" "";Brand=if $PositionFirst != empty then getCaption($PositionFirst/Brand) else "" "")"
I have above code in excel and I want to escape so that I show 2 empty string as value for If condition. But it gives error I tried using 3 like """ """ it is also not working. But when I remove one it works.
How to correctly escape 2 " " in excel
The correct way to escape a " in Excel is to add one more " before it.
By escaping a " you are asking Excel to treat it as literal text.
For example:
"The ""fox"" jumped over the lazy dog"
would evaluate as
The "fox" jumped over the lazy dog
In answer to your example below:
But it gives error I tried using 3 like """ """ it is also not working. But when I remove one it works.
You don't have to encase the problematic character in escape characters, you only need to immediately precede the problematic character with the escape character.

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).

In VBA for Excel, How can I manipulate a header/footer when the string contains '&'

I have a section of code that writes to the header section of the page. The problem is that the string that is written to the header occasionally contains a '&' symbol. This interferes with the code because VBA automatically views & and the following character as a piece of code, even if its part of the string.
ActiveSheet.PageSetup.CenterHeader = "&B&14 Cool New Header for &16 &I" & vbNewLine & aString
Everything works great when aString has no '&' symbol in it. I get a bold, size 14 top line followed by the size 16, italicized aString text on a second line.
In the event that aString is something like 'B&S Company of Greatness' the header will come out with "Company of Greatness" stricken out because of the '&S' contained within the string.
How can I get around this? I'd do a search in string for '&S and compensate manually by inserting another &S to cancel it out but &S might not be the only occurance of the '&' symbol that occurs.
What's the best way to get around this? Would properly diming things help by telling excel to read aString ONLY as a string value and to not apply its contents improperly?
You need to escape the ampersand by adding a second ampersand to each instance in the string, like this:
aString = Replace(aString, "&", "&&")
ActiveSheet.PageSetup.CenterHeader = "&B&14 Cool New Header for &16 &I" & _
vbNewLine & aString

Turn Excel line break into <br>

A client sent me a huge list of product name and descriptions. The Description cells have text wrap and many line breaks. I need to import this into a MySQL which I do through Navicat Premium.
The problem is that the description cell is used as the HTML description of each product page.
Is there a way to replace Excel's line break with the <br> either in the same Excel file or by a php function?
A little bit of ASCII coding will go a long way.
Set up the find/replace dialogue (Ctrl-H). In the Find field, hold down the Alt key and type 010 from the numeric key pad. (This lets you find a linefeed character.) In the replace field, put your <br>.
or use a VBA function to replace the carriage returns in a string
Insert a MODULE and paste this
Function LineFeedReplace(ByVal str As String)
dim strReplace as String
strReplace = "<br>"
LineFeedReplace = Replace(Replace(Replace(Replace(Replace(Replace(str, Chr(10), strReplace), Chr(13), strReplace), vbCr , strReplace), vbCrLf, strReplace), vbLf, strReplace), vbNewLine, strReplace)
End Function
If cell A1 contains a string with a linefeed then =LineFeedReplace(A1) will return the string with all linefeeds set to <br>
First make sure you account for both CR and LF which tend to come together. The codes for these are 0013 and 0010 and so you will need a formula that allows you to clean both. I used this formula successfully =SUBSTITUTE(A3,CHAR(13),"<br>") to convert a cell of long text in excel replacing invisible breaks with the 'br' tag. Since you can't tell exactly what kind of line break you have you can also try it with 0010 or =SUBSTITUTE(A3,CHAR(10),"<br>")

Resources