Xamarin UIActionSheet/UIAlertController multiline text - xamarin.ios

I want to do the same thing as 26408571 but in Xamarin
var alertLabel = UILabel.AppearanceWhenContainedIn(typeof(UIAlertController) don't give me any Lines or LinesNumber method on the returned UILabelApparence.
How can I achieve the same result with Xamarin?

UILabelAppearance doesn't provide property like Lines or LinesNumber.
What do you want ?
To implement multiline text with UIAlertViewController, just refer to the link , add \r in the text string.
UIAlertController alert = UIAlertController.Create("Line1\rLine2", "message", UIAlertControllerStyle.Alert);
this.PresentViewController(alert, false, null);

Related

How would I isolate a string between two strings in DiscordJS?

I've currently been using this script:
var portion = body.substring(
str.lastIndexOf('ID Background',") + 1,
str.lastIndexOf('ID Theme',")
);
"Body" is the input, "Portion" being the output.
I'm trying to isolate text between the words strings "ID Background" and "ID Theme"
Example:
ID Background
Background information Background information Background information Background information
ID Theme
Theme information Theme information Theme information Theme information Theme information
...Et Cetera.
Expected Output:
Background information Background information Background information
Current Output:
undefined
I cannot figure out why this script is not working. I'm using this for a Discord bot (Discord.JS)
You should use RegExp capturing groups ()
// objective: get everything in between 'start' and 'end'
const str = 'start hello how was your day end';
// capture everything in between the two words in parentheses
console.log(str.match(/start (.*) end/)[1]);
Since you're example uses line breaks, which the special character . doesn't cover, you should use [\s\S] (\s is whitespace, and \S is anything but whitespace. Together, they cover everything. Also, use optional chaining ? so that your code doesn't throw a TypeError if no match is found.
var portion = body.match(/ID Background *([\s\S]*) *ID Theme/)?.[1];
if (!portion)
// no match found...

UITextView: how to set the AttributedText with an empty String?

I have an UItextView and i set the AttributedText at the starting of the app so with en empty text because user didn't yet fill anything. The problem is that with an empty String the AttributedText seam to not apply for the new text i will enter. how to do ?
As far as I know there is no straight solution for that. Setting AttributedText with "" doesn't work.
However you can do easy fix:
if let text = field.attributedText?.string {
//normal way
} else {
field.font = ...
field.fontColor = ...
//sorry, no shadow and other nice tricks
}
Of course you could implement delegate to text field and adjust attributes when textFieldDidChange, but that doesn't work well with typing in Chinese language where letter can be composed from multiple characters so I couldn't use that.

How to get first word from sentence in Swift

I am trying to get first word from String sentence as variable. How to do that? I have Local notification and I need to use it's message first word as variable, is it possible? For LocalNotifications I use LocalNotificationHelper library for easier handling. Maybe there is logic problem but I do not think so. More like I do not know enough options in Swift language.
Edit: I also have the nameField.text! in NSUserDefaults as an array. I need to delete the message first word from that array. Right now I remove only the first object from that array but that is not solution for me because I need to delete the nameField.text! from that array when LocalNotification pops out and user click on button.
Here I create notification message:
LocalNotificationHelper.sharedInstance().scheduleNotificationWithKey("text", title: "see options(left)", message: nameField.text!+"some text", date: deadlinePicker.date, userInfo: userInfo)
Now I need the message:nameField.text! to be variable at app launch.
This is how I trigger notification button actions:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "someFunction:", name: IDENTIFIER, object: nil)
Swift 3
let sentence = "First word needed"
let word = sentence.components(separatedBy: " ").first
print(word) // First
You can split your sentence using the white space char and then extracting the first element.
let sentence = "What a wonderful world"
if let firstWord = sentence.characters.split(" ").first.map(String.init) {
print(firstWord) // "What"
}

Finding string in the textfield. Actionscript

What is the best way to find a string (sentence of 1-3 lines) in the multiline textfield.
I have a textfield with a list of messages. In order to change every second messages color, i have to get the index where this message beggins.
ANy ideas?
I solved my problem. Maybe it will be useful for someone.
As i'm appending text, i use textfield.caretIndex to see the inserts. So i'm switching formats using this function:
if (i % 2 != 0) {
textfield.setTextFormat(colorFormat, lastCaret , textfield.caretIndex);
formatStart = textfield.caretIndex;
}
else {
textfield.setTextFormat(textFormat, formatStart, textfield.caretIndex);
lastCaret = textfield.caretIndex;
}

How to compare 2 strings if one string is plain and second contains some html tags

I have some line of statements in my database.Whenever I create an article and add any line of these statements in this article manually then I have to find these lines and make them link.
problem is that I am using ckeditor for article posting and user can add style to text also. So I have to maintain style of matched line and also make that link.
statements (saved in a table):
1: this is first line
2: this is second line
3: this is third line
Article to be created :
this is my article , this is <span style="color:red">first</span> line. rest of article.
Now when user add this article then (1) line should be matched and in article it should be appear as :
this is <span style=".">first</span> line
Hope I stated my problem clearly.
Thanks in advance.
Try this
string mysql_real_escape_string ( string $unescaped_string [, resource $link_identifier ] )
With PHP, this should get you started:
$string_without_tags = strip_tags($string_with_tags);
PHP.net strip_tags Manual
Remove the html tags. Then compare. You can use the following javascript to remove.
public static String html2text(String html) {
return Jsoup.parse(html).text();
}
Pattern for this is :
$pattern = "/(<?.*>)?this(<\/?.*>)? (<?.*>)?is(<\/?.*>)? (<?.*>)?first(<\/?.*>)? (<?.*>)?line(<\/?.*>)?;
preg_match_all($pattern,$str,$matches);
$replacement="<a href='#'>".$matches[0][0]."</a>";
$str = preg_replace($pattern,$replacement,$str,-1);

Resources