How can I check what exactly and where a string changed in my textfieldDidChange method?
let str1 = "Hello how are you #Marie, nice day uh?"
So imagine my user decides to edit the text and link markus instead of marie
let str2 = "Hello how are you # Markus, nice day uh?"
I need a method that detect the change of # Markus in the text field but doesn't change anything else in the string.
I am able to detect last word, first word and so one, but its important to also see what changed within the text
i am thinking about a method that
a = "Hello how are you"
b = newly changed text field
c = ", nice day uh?"
let str3 = a + b + c // More or less
Maybe that I get the index where I am editing at, taking the word out at this index - from left space to right space - and cutting it out?
Thanks in advance, yes I am a beginner :P
If you set your view controller up to be the delegate of your text field, you can implement the textField(_:shouldChangeCharactersIn:replacementString:) delegate method. That will tell you the range of characters that the user has asked to change, as well as providing the replacement string.
You could use that to monitor the user's edits. However, the string can easily get changed in a way that is difficult to track. What if the user deletes the "Hello how are you " part? What if they replace the whole string with "Shut your festering gob #fred, you malodorous pervert"?
You're probably better off getting the whole string from the text field and parsing it. You could accept anything the user enters, an look for and # sign, and take everything after that until the next space as the name, e.g. #alphanumerics`
Edit:
Alternately, you could set up your screen so the first part is a label, the middle part is an editable text field, and the last part is another label. The only part the user is able to edit is the middle part, the name. Or you could make it 3 separate text fields, the prefix, the name, and the suffix. Tell the user what you expect them to enter into each part.
You can split your string using this code.
For Objectve c :
1. Create function like this.
-(NSString *)checkString:(NSString *)splitString{
NSRange firstObj = [splitString rangeOfString:#"#"];
NSRange secondObject = [splitString rangeOfString:#","];
NSRange rangeSubStr = NSMakeRange(firstObj.location + firstObj.length, secondObject.location - firstObj.location - firstObj.length);
return [splitString substringWithRange:rangeSubStr];
}
2. Use this function like this.
[self checkString:#"Hello how are you #Marie, nice day uh?"]
Then every change in text, you can check substrings, and compare them to original substrings.
Related
I need a Google Sheet function that will return the position of the last instance of a particular character. Basically, FIND, but starting on the right.
For example, for the data set below, I need to return the position of the last dash.
ABC-DEF-GHI = 8
ABCD-EF-GH-IJK = 11
AB-C-DE-FGH-I-JK = 14
Thanks!
I don't know where to start. MID might work, but the file names are of different lengths and different formats. The files just generally end with - ***.png, and I need the asterisk. The string I need is also of variable length and can contain spaces (the string is the name of the student).
Here's a possible solution:
=len(regexextract(A1,".*-"))
It's essentially extracting everything up to the last dash and taking the length of the resulting string.
for the whole array try:
=INDEX(LEN(REGEXEXTRACT(A1:A3; "(.*-)")))
I have 1000's of record in a database and I have one field as name and other as code
now i want to replace all code with every 1st letter after space from name for example
in name field
Manoj Sir Madan then replace code will be "MSM"
Suraj Bhai Bhanu then replace code will be "SBB"
Aayush Deepak Bhanu then replace code will be "ADB"
1st letter from start then every 1st letter after space
I do not have code nor did I find any
Can any one help me with this
So I am going around this the long way but what I am trying to do is extract the text in the center of a cell with text on both sides of it.
Example Text is:
Alliance: CRAZY CATS (Neutral)
Alliance: Dark Arts (Yours)
Alliance: Portal (Hostile)
I want to extract everything between : and (
In these cases I only need the name of the alliance the person is in. I tried to do a regedit but didn't completely understand it. I tried a few different formulas but was only able to remove either the first part or the last part and I could push them to two different cells but couldn't get them to work together in the same cell.
You can use REGEX functions, but I find that not everyone understands them. So here, I'll supply a non-REGEX solution.
Supposing your sample data were in A2:A4 (with some header in A1), place the following in B2 (or row 2 of any other column):
=ArrayFormula(IF(A2:A="","",TRIM(MID(A2:A,FIND(":",A2:A)+1,FIND("(",A2:A)-FIND(":",A2:A)-1))))
=REGEXEXTRACT(A2, ":\s*([^(]+)\s*\(")
: literal ":"
\s* zero or more space characters
() capture group
[^(]+ one or more of any character except (
\( literal (
See
What does this regex mean?
Tag info page
So in the leaderboard I have cash, exp, etc. But I also want to have a "Title" option, the thing is that if I want to change the stat, I dont know how to change it to words instead of numbers, can anyone help me?
What you'd be looking for is a StringValue. These can store strings of text instead of numbers, booleans, etc.
local stringValue = Instance.new("StringValue", [player].leaderstats)
stringValue.Value = "Your text here"
This question already has answers here:
UITextView change text color of specific text
(3 answers)
Closed 7 years ago.
I have an iOS Swift 2/Xcode 7 project that searches a string and identifies substrings from a specified list. The input string will change, but the substrings remain the same.
Something like this
inputString "SALT, WATER, FLOUR"
Comparison substrings "SALT, PEPPER"
Since "SALT" is present, it would become highlighted to look like this
SALT WATER FLOUR
and ideally in a different color - so Red for "SALT", Green for "PEPPER", anything else would be black.
Here is the basic code for searching for the substrings -
iList = "SALT, FLOUR, WATER...." //actually pulled from CORE data, different for every search
for ingredient in ["SALT", "PEPPER", "SUGAR"] {
if iList.rangeOfString(ingredient) != nil {
print("Ingredient Found \(ingredient) found")
}
}
The iList is displayed in a TextView.
The desired result would look something like
SALT, FLOUR, WATER....
The examples I found relied on being able to change text colors at specific positions within the string. In this case, the location of a substring (if present) will vary for every use.
Help with this would be greatly appreciated.
Thank you.
You need to use NSAttributedString for this purpose.
Check out this post:
http://ramezanpour.net/post/2014/01/28/customize-your-texts-in-ios-using-nsattributedstring/
Use substringWithRange method to find the range of the string that you need to make bold or change color and then use the returned range as shown in the tutorial.