how to implement android search in windows application desktop vb.net c# sharp [Resolved]

Posted by Ermahesh2009 under Sql Server on 10/8/2015 | Points: 10 | Views : 560 | Status : [Member] | Replies : 5
Here I want to Implement a search like android . like return those Rows of column which any of its word begin with what user search .

I have a column named suppose ArticleName values Like

Mahesh Nagar
Manish Nagar
Shan mani
Ghanshaym rama

Now when i start search 'MA' result would be
<B>Ma</B>hesh Nagar
<B>Ma</B>nish Nagar
Shan <B>ma</B>ni

Ghanshaym rama should not select as it contains ma but second word not start with ma.

AND when Type "SH"
Result would be
<B>Sh</B>an mani
same other rows are exclude because in column value not any of word start with sh




Responses

Posted by: Rajnilari2015 on: 10/8/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
2
Down

Resolved
Try

using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
List<string> lstNames =
new List<string>() { "Mahesh Nagar", "Manish Nagar",
"Shan Mani", "Ghanshaym rama" };
string toSearch = "Sh";
string[] stringSeparators = new string[] { " " };
lstNames
.ForEach( str=>
{
if (str
.Split(stringSeparators, StringSplitOptions.None)
.Any(i => i.StartsWith(toSearch))
)
Console.WriteLine(str.Replace(toSearch, "<b>" + toSearch + "</b>"));
});
Console.ReadKey();
}
}
}

Result
<b>Sh</b>an Mani

Change: string toSearch = "Ma";
Result
<b>Ma</b>hesh Nagar

<b>Ma</b>nish Nagar
Shan <b>Ma</b>ni

Hope this helps

--
Thanks & Regards,
RNA Team

Ermahesh2009, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 10/9/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
2
Down

Resolved
SQL Server Version


DECLARE @t TABLE (ArticleName VARCHAR(100))
INSERT INTO @t VALUES('Mahesh Nagar'),('Manish Nagar'),('Shan mani'),('Ghanshaym rama')
DECLARE @toSearch VARCHAR(20) = 'MA'
DECLARE @delimeter VARCHAR(10) = ' '

SELECT
X.ArticleName
, CASE WHEN
PATINDEX ( '%'+ @toSearch +'%' , LEFT(Y.SplitArticleNames,LEN(@toSearch))) > 0
THEN REPLACE(X.ArticleName,@toSearch,'<b>' + @toSearch + '</b>')
ELSE Y.SplitArticleNames
END AS ReplacedValues
FROM (
SELECT
*
,ReplaceValue = CAST('<X>'+REPLACE(S.ArticleName,@delimeter,'</X><X>')+'</X>' AS XML)
FROM @t S
)X CROSS APPLY (
SELECT SplitArticleNames = Data.d.value('.','varchar(50)')
FROM X.ReplaceValue.nodes('X') AS Data(d))Y
WHERE PATINDEX ( '%'+ @toSearch +'%' , LEFT(Y.SplitArticleNames,LEN(@toSearch))) = 1

Result
--------

ArticleName	ReplacedValues

Mahesh Nagar <b>Ma</b>hesh Nagar
Manish Nagar <b>Ma</b>nish Nagar
Shan mani Shan <b>Ma</b>ni

Change
DECLARE @toSearch VARCHAR(20) = 'SH'

Result
ArticleName	ReplacedValues

Shan mani <b>SH</b>an mani


--
Thanks & Regards,
RNA Team

Ermahesh2009, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 10/8/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
VB.net version
Tool use : http://converter.telerik.com/


Imports System
Imports System.Collections.Generic
Imports System.Linq

Namespace ConsoleApplication2
Class Program
Private Shared Sub Main(args As String())
Dim lstNames As New List(Of String)() From { _
"Mahesh Nagar", _
"Manish Nagar", _
"Shan Mani", _
"Ghanshaym rama" _
}
Dim toSearch As String = "Ma"
Dim stringSeparators As String() = New String() {" "}
lstNames.ForEach(Function(str)
If str
.Split(stringSeparators, StringSplitOptions.None)
.Any(Function(i) i.StartsWith(toSearch)) Then
Console.WriteLine(str.Replace(toSearch, (Convert.ToString("<b>") & toSearch) + "</b>"))
End If
End Function)
Console.ReadKey()
End Sub
End Class
End Namespace

'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: @telerik
'Facebook: facebook.com/telerik
'=======================================================



--
Thanks & Regards,
RNA Team

Ermahesh2009, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ermahesh2009 on: 10/12/2015 [Member] Starter | Points: 25

Up
0
Down
thanks Rajnilari2015

it is great help and even its great for me to know this things exists .

Ermahesh2009, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 10/12/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
Glad that it has helped you. (:

--
Thanks & Regards,
RNA Team

Ermahesh2009, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response