Angular material auto complete should show options if the value matches with starting letter(s) of any word - autocomplete

The first typed letter should match the first letter of every word of the result in the drop down.
Currently I am matching with any letter in the option like below but I should be match only starting letter(s) of any word in the option.
My current logic is below,
return this.allUniversities.filter(university => university.toLowerCase().indexOf(filterValue) > -1);
If the entry in the list is Industrial Designer, then this entry should show up if a candidate types the letter I or the letter D. It should not show up if the candiate types the letters ‘N, D, U, S’ etc.

All you need to do is split the string and then check if the substrings start with the typed characters:
return this.allUniversities.filter(university => {
return university.toLowerCase().split(' ').some(substr => substr.startsWith(filterValue));
});
Here
is a stackblitz that shows it in action.

Related

Pascal, I have to introduce a letter and number and using boolean to find the value of this sentence ,,This letter has the alphabetical order = N''

The problem should be solved with boolean. I have to introduce a letter and then a number, and to find with the sentence is true or false. for example if i typed a and 1 it should be true. Also the capital letters also count. Sounds like a dumb and easy program but i really don t know how to do it. I don t really know where is the mistake but i think it is on the line 14, 15 and 16, where boolean is. When i run the program it doesn't show the right answer.
Program P14;
var N,m,y,e:integer;
a:char;
T,P,Q,Z:boolean;
begin
writeln('type a letter '); readln(a);
m:=ord(a);
writeln('give a natural number N '); readln(N);
e:=m-64;
y:=m-96;
P:=(64<m) and (m<91) or (96<m) and (m<123);
writeln('it is a letter - ',P);
Q:=(e<30) and (m<91) and (m>64);
Z:=(y<30) and (m>96) and (m<123);
T:= P=true and Q=true or P=true and Z=true;
writeln('This letter has the alphabetical order = N - ',T);
end.

How to check is the text is in right format? Flutter

I'm having a condition as the particular text must be in the particular format where in I'm getting the text from the scanner and need to check if it is in the right format.
The format comes like
The starting letter must start with e or E, next letter might be any letter from a to z or A to Z alphabets, next 9 characteres must be numbers and the last two characters must be from anything within a to z or A to Z alphabets
I tried something like
if (_scannedCode.startsWith('e|E') && _scannedCode[1].startsWith('a-zA-Z') && _scannedCode.substring(2, 10))
but got struck.
Seeing the answers did get the condtions correctly but was struck up with one, so just wanted to get a clarification if its right or not
RegExp emo = new RegExp(r'[0-9]{6}(EM|em|eM|Em){2}[0-9]{10}$');
As i needed the first 6 characters to be numbers the next two characters be alphabet(em) and the remaining 10 characters be numbers.
final regex = RegExp(r'(e|E)[a-zA-z]\d{9}[a-zA-z]{2}');
if (_scannedCode.length == 13 && regex.hasMatch(_scannedCode) ) {
// your code
}

iText PDFSweep RegexBasedCleanupStrategy not work in some case

I'm trying to use iText PDFSweep RegexBasedCleanupStrategy to redact some words from pdf, however I only want to redact the word but not appear in other word, eg.
I want to redact "al" as single word, but I don't want to redact the "al" in "mineral".
So I add the word boundary("\b") in the Regex as parameter to RegexBasedCleanupStrategy,
new RegexBasedCleanupStrategy("\\bal\\b")
however the pdfAutoSweep.cleanUp not work if the word is at the end of line.
In short
The cause of this issue is that the routine that flattens the extracted text chunks into a single String for applying the regular expression does not insert any indicator for a line break. Thus, in that String the last letter from one line is immediately followed by the first letter of the next which hides the word boundary. One can fix the behavior by adding an appropriate character to the String in case of a line break.
The problematic code
The routine that flattens the extracted text chunks into a single String is CharacterRenderInfo.mapString(List<CharacterRenderInfo>) in the package com.itextpdf.kernel.pdf.canvas.parser.listener. In case of a merely horizontal gap this routine inserts a space character but in case of a vertical offset, i.e. a line break, it adds nothing extra to the StringBuilder in which the String representation is generated:
if (chunk.sameLine(lastChunk)) {
// we only insert a blank space if the trailing character of the previous string wasn't a space, and the leading character of the current string isn't a space
if (chunk.getLocation().isAtWordBoundary(lastChunk.getLocation()) && !chunk.getText().startsWith(" ") && !chunk.getText().endsWith(" ")) {
sb.append(' ');
}
indexMap.put(sb.length(), i);
sb.append(chunk.getText());
} else {
indexMap.put(sb.length(), i);
sb.append(chunk.getText());
}
A possible fix
One can extend the code above to insert a newline character in case of a line break:
if (chunk.sameLine(lastChunk)) {
// we only insert a blank space if the trailing character of the previous string wasn't a space, and the leading character of the current string isn't a space
if (chunk.getLocation().isAtWordBoundary(lastChunk.getLocation()) && !chunk.getText().startsWith(" ") && !chunk.getText().endsWith(" ")) {
sb.append(' ');
}
indexMap.put(sb.length(), i);
sb.append(chunk.getText());
} else {
sb.append('\n');
indexMap.put(sb.length(), i);
sb.append(chunk.getText());
}
This CharacterRenderInfo.mapString method is only called from the RegexBasedLocationExtractionStrategy method getResultantLocations() (package com.itextpdf.kernel.pdf.canvas.parser.listener), and only for the task mentioned, i.e. applying the regular expression in question. Thus, enabling it to properly allow recognition of word boundaries should not break anything but indeed should be considered a fix.
One merely might consider adding a different character for a line break, e.g. a plain space ' ' if one does not want to treat vertical gaps any different than horizontal ones. For a general fix one might, therefore, consider making this character a settable property of the strategy.
Versions
I tested with iText 7.1.4-SNAPSHOT and PDFSweep 2.0.3-SNAPSHOT.

How can I obtain only word without All Punctuation Marks when I read text file?

The text file abc.txt is an arbitrary article that has been scraped from the web. For example, it is as follows:
His name is "Donald" and he likes burger. On December 11, he married.
I want to extract only words in lower case and numbers except for all kinds of periods and quotes in the above article. In the case of the above example:
{his, name, is, Donald, and, he, likes, burger, on, December, 11, he, married}
My code is as follows:
filename = 'abc.txt';
fileID = fopen(filename,'r');
C = textscan(fileID,'%s','delimiter',{',','.',':',';','"','''});
fclose(fileID);
Cstr = C{:};
Cstr = Cstr(~cellfun('isempty',Cstr));
Is there any simple code to extract only alphabet words and numbers except all symbols?
Two steps are necessary as you want to convert certain words to lowercase.
regexprep converts words, which are either at the start of the string or follow a full stop and whitespace, to lower case.
In the regexprep function, we use the following pattern:
(?<=^|\. )([A-Z])
to indicate that:
(?<=^|\. ) We want to assert that before the word of interest either the start of string (^), or (|) a full stop (.) followed by whitespace are found. This type of construct is called a lookbehind.
([A-Z]) This part of the expression matches and captures (stores the match) a upper case letter (A-Z).
The ${lower($0)} component in the regex is called a dynamic expression, and replaces the contents of the captured group (([A-Z])) to lower case. This syntax is specific to the MATLAB language.
You can check the behaviour of the above expression here.
Once the lower case conversions have occurred, regexp finds all occurrences of one or more digits, lower case and upper case letters.
The pattern [a-zA-Z0-9]+ matches lower case letters, upper case letters and digits.
You can check the behavior of this regex here.
text = fileread('abc.txt')
data = {regexp(regexprep(text,'(?<=^|\. )([A-Z])','${lower($0)}'),'[a-zA-Z0-9]+','match')'}
>>data{1}
13×1 cell array
{'his' }
{'name' }
{'is' }
{'Donald' }
{'and' }
{'he' }
{'likes' }
{'burger' }
{'on' }
{'December'}
{'11' }
{'he' }
{'married' }

swift, how i find the letter that i want in sentence or word?

I want to find letter in variable a,
what is code for searching method?
Example:
var a = ["coffee","juice","water"]
search letters is "co"
searching method's result is "cofee",
what is searching method?
First you need to iterate over an array and select elements which match some condition, there's a filter method for that. In this case you need to check if a word contains some string, so use containsString.
a.filter { $0.containsString("un") }