sort nsarray by second word. (by surname in "firstname surname" kind of strings array)
Tag : ios , By : delphiace
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I am having nsarray of strings like "fistname surname". Now I want to sort that strings array by second word i.e. by surname. I used this method , You can do sort like, NSArray *sortedArray = [teacherList sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
NSString *firstTeacher2ndWord = [[[[(Teacher*)a name] componentsSeparatedByString:@" "] objectAtIndex:1] lowercaseString];
NSString *secondTeacher2ndWord = [[[[(Teacher*)b name] componentsSeparatedByString:@" "] objectAtIndex:1] lowercaseString];
return [firstTeacher2ndWord compare:secondTeacher2ndWord];
}];
//Assuming in above you have atleast 2 words in name
//i.e. objectAtIndex:1 doesn't fail or you need to put condition
//there according to your needs
@interface Teacher : NSObject
@property (nonatomic,strong) NSString *name;
@end
NSArray *sortedArray = [[teachersList allValues] sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
NSString *firstTeacher2ndWord = [[[((NSString*)a) componentsSeparatedByString:@" "] objectAtIndex:1] lowercaseString];
NSString *secondTeacher2ndWord = [[[((NSString*)b) componentsSeparatedByString:@" "] objectAtIndex:1] lowercaseString];
return [firstTeacher2ndWord compare:secondTeacher2ndWord];
}];
|
Grouping based on two elements (surname and firstname) even if surname contains entities
Tag : xslt , By : user181945
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Suggest for how to group the Index entries based on surname and firstname (some times surname may starts with entity like Ŕ, then those surname should be sorted in R series). My code is unable to give element name for surname and firstname. (XSLT ver 2) , At last I got the answer, please check whether this OK or not. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes" use-character-maps="chars"/>
<xsl:include href="Unicode.xsl"/>
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy>
</xsl:template>
<xsl:template match="index">
<cmindexnote><xsl:value-of select="cmindexnote"/></cmindexnote>
<issue><xsl:value-of select="issue"/></issue>
<xsl:for-each-group select="author" group-by="concat(lastname, firstname)">
<xsl:sort select="lastname" collation="http://saxon.sf.net/collation?lang=en&ignore-modifiers=yes"/>
<xsl:sort select="current-grouping-key()" collation="http://saxon.sf.net/collation?lang=en&ignore-modifiers=yes"/>
<author>
<lastname><xsl:value-of select="*[1]"/></lastname>
<firstname><xsl:value-of select="*[2]"/></firstname>
<xsl:apply-templates select="current-group()">
<xsl:sort select="number(refserial/serno)"/>
</xsl:apply-templates>
</author>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="author">
<xsl:apply-templates select="node() except (lastname, firstname)"/>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:character-map name="chars">
<xsl:output-character character="Ŕ" string="&Racute;"/>
</xsl:character-map>
</xsl:stylesheet>
|
Uppercase surname, excluding the lowercase prefix section of a surname
Tag : php , By : Chris Woods
Date : March 29 2020, 07:55 AM
this one helps. Going with the rule to capitalise everything after the last capital letter: preg_replace_callback('/\p{Lu}\p{Ll}+$/u',
function ($m) { return mb_strtoupper($m[0]); },
$name)
preg_replace_callback('/[A-Z][a-z]+$/',
function ($m) { return strtoupper($m[0]); },
$name)
|
Similarity search for name surname
Date : March 29 2020, 07:55 AM
hop of those help? You should read about the pg_trgm extension and its function similarity(). A few examples below. Example data: create table my_table(id serial primary key, name text);
insert into my_table (name) values
('John Wilcock'),
('Henry Brown'),
('Jerry Newcombe');
create extension if not exists pg_trgm; -- install the extension
select *,
similarity(name, 'john wilcock') as "john wilcock",
similarity(name, 'wilcock john') as "wilcock john"
from my_table;
id | name | john wilcock | wilcock john
----+----------------+--------------+--------------
1 | John Wilcock | 1 | 1
2 | Henry Brown | 0 | 0
3 | Jerry Newcombe | 0.037037 | 0.037037
(3 rows)
select *,
similarity(name, 'henry brwn') as "henry brwn",
similarity(name, 'brovn henry') as "brovn henry"
from my_table;
id | name | henry brwn | brovn henry
----+----------------+------------+-------------
1 | John Wilcock | 0 | 0
2 | Henry Brown | 0.642857 | 0.6
3 | Jerry Newcombe | 0.04 | 0.0384615
(3 rows)
select *
from my_table
where similarity(name, 'J Newcombe') >= 0.6;
id | name
----+----------------
3 | Jerry Newcombe
(1 row)
|
How to select all records that match with the concatenation of (name, surname) OR (surname, name)
Date : March 29 2020, 07:55 AM
wish of those help You got two placeholders ? in your query-string but only binding one variable to the statement. Try to bind it a second time, so the count matches. mysqli_stmt_bind_param($stmt, "ss", $param_term, $param_term);
|