Problems with string manipulation in an UltraEdit script - ultraedit

Inside an UltraEdit script I've got a bit of code like so:
var FNstring = UltraEdit.activeDocument.selection;
var FNstring = UltraEdit.activeDocument.selection.replace(">>","</p>");
var FNstring = UltraEdit.activeDocument.selection.replace("\r\n","<BR>");
A var_dump confirms that the content of the string at this moment is:
text text text
text text text text text text text text text
text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text>>
I'm just not getting those find/replace commands right:
Replace the >> with (/p) (once only)
Replace all CR/LF with (br). (0 or >1 )
That code above is just not doing it. I'm getting something wrong. How can I fix this?

Those three lines of code do the following:
Create a copy of the selection in the active document in UltraEdit into a JavaScript string variable.
Create a copy of the selection in active document in UltraEdit into a JavaScript string variable with the same name as before, resulting in discarding the previous string and additionally replacing >> by </p> in the created copy.
Create a copy of the selection in active document in UltraEdit into a JavaScript string variable with the same name as before, resulting in discarding the previous string and additionally replacing \r\n by <BR> in the created copy.
That is not what you want. The replace function of the JavaScript String object has nothing to do with the replace function of the UltraEdit document object.
You could use instead following two lines:
var FNstring = UltraEdit.activeDocument.selection.replace(/>>/g,"</p>");
UltraEdit.activeDocument.write(FNstring.replace(/\r\n|\n|\r/g,"<BR>"));
Those two lines do following:
Create a copy of the current selection in the active document of UltraEdit into the JavaScript string variable FNstring with replacing all occurrences of >> by </p> in the created copy.
Create one more copy of the previously created string FNstring with replacing all occurrences of a DOS (Windows) or UNIX or Mac line termination by <BR> and write this new string over the selection in the active document of UltraEdit.

Related

How to disable text formatting when pasting in summernote editor?

How to disable text formatting when pasting in summernote editor?
how to turn off text formatting, for example when you paste with word, etc. adds a bunch of unnecessary styles all the time. Is it possible to make it paste plain text without formatting?
By using summernote.paste event we can track the paste in the editor and then text can be formatted or unnecessary style can be removed.
$('#id').on('summernote.paste', function(e, ne) {
//get the text
let inputText = ((ne.originalEvent || ne).clipboardData || window.clipboardData).getData('Text');
// block default behavior
ne.preventDefault();
//modify paste text as plain text
let modifiedText = inputText .replace(/\r?\n/g, '<br>');
//put it back in editor
document.execCommand('insertHtml', false, modifiedText );
})

How to get the range and Cursor Position in UITextView

Hello I'm trying to create a custom text editor, for which I want to know the position of the cursor and range of the text in UITextView for which I can apply TextAttributes based on the user selected options.
For eg:
\n This is a the first paragraph string \n This is the second paragraph string \n
For this string, if the cursor is anywhere in the first paragraph string, and user select some text attribute, then I want to change only the This is a the first paragraph string based on selection.
For now, I know this can be achieved using multiple text attributes for specific range.I'm unable to get the range based on the cursor and break characters.
I'm new to this. If there is some other way to achieve this please let me know. Thanks

Read long paragraph of text from plist into a specific format with swift 3

I am currently writing my first app on ios using swift 3. I have a plist that has a list of different pieces of information and each is a long paragraph with sections throughout it. for each section, I want to bold the text for the title or at least have the option to format it a certain way rather than just display all the text. I currently have a simple table view that displays text in a text view once tapped. I cannot figure out how to read the paragraph into a string, and compare parts of the string and bold that specific text.
For example, If I had a string that was read from the plist and said:
"My name is #Bob and I like to #dance."
How could I change "#Bob" to "Bob" and "#dance" to "dance" without hard coding it?
#IBOutlet var paragraphTextView: UITextView!
.
.
.
if let text = paragraph["Text"] {
paragraphTextView.text = text
}
The simplest solution is to use some HTML markup in the text in your plist file.
Instead of the plain text:
My name is #Bob and I like to #dance.
Use:
My name is <b>Bob</b> and I like to <b>dance</b>.
This gives you far more flexibility. You can add bold, underline, and italic simply by using the appropriate <b></b>, <u></u>, and <i></i> tags as needed. It also allows you to markup more general ranges than single words.
Once the text has the proper markup, you create an NSAttributedString from the marked up string and then set that to the text viewsattributedTextproperty instead of using thetext` property.
For a good example of how to create an NSAttributedString from HTML text, see HTML Format in UITextView

Formatting a letter on textView in iOS

I have two pages long letter in textView. And all context of the letter should be shown in device's screen. I'm trying to achieve this by making the font smaller. The problem is that if I copy the letter into textView, it changes the font color to all black and format of the letter becomes weird.
I tried to edit the letter format in Storyboard but it's very hard. When I try to press "Enter" in textView, it doesn't put space between the lines but rather I come out from the textView.
Is textview the best place to put long context of the letter in? If so, how should format the letter in there?
To enter space use Option+Enter and if you are copying from text editor that support formatting then please remove all formatting then copy and paste it. to format text in textview use attributed string.
Why don't you format it in text editor and save it to a rtf file then, read the rtf into an attributed string, then set the attributedText of the text view? Like:
let textURL = NSBundle.mainBundle().URLForResource("MyLovelyLetter", withExtension: "rtf")
let options =[NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType]
let attribText = try! NSAttributedString(fileURL: textURL!, options: options, documentAttributes: nil)
textView.attributedText = attribText
for example

Preserve text style when changing Text view text

I have a Text View with attributed text, with some style, set in Xcode utilities pan. Basically, a font, a size, and an alignement.
Then programmatically I change text of the view:
self.myView.text = "New text"
It does change the text, but discard all style of the text and use a default style.
I tried self.myView.attributedText = "New text" but got a protocol conformance issue.
What's the correct strategy to deal with this ?
Is there a way to inject the new text while preserving style ?
Or should I reset style manually each time I change text ?
(please answer in swift if possible)
Basically you need to create an NSAttributedString with the desired text and formatting (font and text alignment).
Then assign the attribute string to the text field's attributedText property.

Resources