In SwiftUI how can i make Text to show Double Backslashes?
Escaping does not seem to help
Text("Hello \\\\") // renders to: Hello \
Expected Output: Hello \\
Raw Strings is not an option here, as localization is not possible without the right escape sequence.
Localization of the String MUST be possible!
Here is possible variant
Text(verbatim: "Hello \\\\")
Tested with Xcode 13.3 / iOS 15.4
Related
there's an issue with SwiftUI's Text view while having multiple lines. So just look:
var body: some View {
Text("Some word Some word Some word Some word")
.frame(maxWidth: .infinity, alignment: .leading)
.border(.red)
.padding(16)
}
However adding one word changing the wrapping:
As result the view doesn't look as expected, for bigger fonts the difference become more visible:
Environment: iOS 15.2, Xcode 13 / Xcode 14b Preview and Simulator
Is there a reliable solution to wrap strings similarly as UILabel do without using UIViewRepresentable?
PS: already tried different combinations with .fixedSize() + .frame(idealWidth:) and no luck
Apple is following typography rules. One of those rules is to avoid having a single word on the last line of a paragraph. This runt, as it is called, is believed to break a reader's focus due to all the white space. However, if the last word and any trailing punctuation is greater than 10 characters this rule does not apply.
No option exists to turn this rule off directly to my knowledge. But a workaround is to use trailing spaces at the end of the text where this could occur. Use enough trailing spaces to make the last line have greater than 10 characters.
Using your example, adding 7 trailing spaces works. "Some" plus 7 spaces being 11 characters:
Text("Some word Some word Some word Some word Some ")
In this example, 8 trailing spaces works. "the" plus 8 spaces provides 11 characters so the rule does not apply and the line breaks where desired:
Text("Some word to demonstrate the ")
And with the trailing spaces, the layout should look ok with larger devices and when orientation changes occur. Fortunately the trailing spaces are truncated and will not create a new line on their own.
extension String {
var padded: String { self + " " }
}
Usage:
Text("Some word to demonstrate the".padded)
Side note: UILabel(versions 13.0, 16.1) also appears to use these typography rules by default. But a UILabel can turn off this typography rule with the line break strategy setting:
label.lineBreakStrategy = NSParagraphStyle.LineBreakStrategy()
Or like this:
label.lineBreakStrategy = []
But it doesn't appear to be available in SwiftUI yet.
I tried below in POSTMAN
console.log('Hello World');
console.log("Hello World");
Showing output in console as below in both the cases
"Hello World"
How to remove those quotation marks and print plain text in POSTMAN console like
Hello World
the syntax is :
console.log(val)
Different ways to represent string is to enclose the string with anyof :
double quotes :" , single quotes: ' and string literal: `
if you want to have string with the quotes escape it out or enclose with a different one
console.log("'Hello world'")
console.log("\"Hello world\"")
console.log('"Hello world'")
console.log(`"'Hello world"'`)
There is no built in way... but if you really want to follow these steps.
View > Developer > Show DevTools (Current Window)
Navigate to the Elements tab in the DevTools
ctrl + f for wf__qt (this will show you the element that holds the quotes
click on this element to see it's styles
in the styles pane, find the wf__qt class and uncheck the content: '"' style
I'm looking for format a text to automatically capitalise the first letter of every word
Text("hello world")
Will show as:
Hello World
Any Swift (NS)String API can be used also in SwiftUI
Text("hello world".capitalized)
I want to show a php function with a regex in a code snippet using the lstlisting package. TeX gives me several errors "Package inputenc Error: Invalid UTF-8 byte sequence" and the dollar sign seems to put my tex code in math mode. The whole document is UTF-8 encoded. Any ideas how to correctly deal with these special chars in lstlisting environment? Thanks.
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\begin{lstlisting}[language=php,label={lis:mylisting}]
public function passes($attribute, $value)
{
return preg_match("/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[0-9])(?=.*?[#?!#()$%^&*=_{}[\]:;\"'|\\<>,.\/~`±§+-]).{8,255}$/", $value);
}
\end{lstlisting}
The problem is the plus-minus and section symbol. You can add specify them as literate:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[language=php,label={lis:mylisting},extendedchars=true,literate={±}{{$\pm$}}1 {§}{{\S}}1]
public function passes($attribute, $value)
{
return preg_match("/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[0-9])(?=.*?[#?!#()$%^&*=_{}[\]:;\"'|\\<>,.\/~`±§+-]).{8,255}$/", $value);
}
\end{lstlisting}
\end{document}
Requirement;
All Special characters allowed excluding (`) (') () (") and Spaces
using below for the same and working fine in ios 10
const UserIdRegExp = /[^`"' \\]$/g;
not working in ios11
const value='anand`';
when i am doing UserIdRegExp.test(value);
ios10 return false.
and ios11 return true
In iOS 11 Apple introduced "Smart Punctuation", which automatically slants certain punctuation marks based on content.
const regex = /[^`"“”'‘’ \\]$/g;
Example:
iOS 10: "double quotes", 'single quotes'
iOS 11 (with Smart Punctuation on): “double quotes”, ‘single quotes’