I needed to replace the \r\n with actual carrige return and line feed and replace \t with actual tab. So I came up with the following:
|
-
-
public bool IsPalindrome(string stringToCheck)
{
char[] rev = stringToCheck.Reverse().ToArray();
return (stringToCheck.Equals(new string(rev), StringComparison.OrdinalIgnoreCase));
}
0Add a comment
-
Lets say we have two tablesProperty Table:PropIDPropertyValue1aaa1112bbb2223ccc3334ddd4445eee5556fff666
And user table:UserIDNamePropID1User111User121User132User232User243User354User46
We need results in the format:1User1111:222:3332User2333:4443User35554User4666
DECLARE @tblProperties table (PropID int, Property varchar(20), Value varchar(20))DECLARE @tblUsers table (UserID int, Name varchar(20), PropID Int)
INSERT @tblProperties (PropID, Property, Value)SELECT 1, 'aaa', '111'UNION ALLSELECT 2, 'bbb', '222'UNION ALLSELECT 3, 'ccc', '333'UNION ALLSELECT 4, 'ddd', '444'UNION ALLSELECT 5, 'eee', '555'UNION ALLSELECT 6, 'fff', '666'
INSERT @tblUsers (UserID, Name, PropID)SELECT 1, 'User1', 1UNION ALLSELECT 1, 'User1', 2UNION ALLSELECT 1, 'User1', 3UNION ALLSELECT 2, 'User2', 3UNION ALLSELECT 2, 'User2', 4UNION ALLSELECT 3, 'User3', 5UNION ALLSELECT 4, 'User4', 6
CREATE TABLE #TempTable(ID int, Name varchar(20), Property varchar(20), Value varchar(20) )CREATE TABLE #TempTable2(ID int, Value varchar(20) )
--INSERT The combined data into first temp table.INSERT INTO #TempTableSELECT t.UserID, t.Name, p.Property, p.Value FROM @tblProperties p, @tblUsers tWHERE t.PropID = p.PropID
--Merge the data where user id are same - seperate the values by ":"INSERT INTO #TempTable2SELECT distinct (tTable.ID),Left(tTable.Value,Len(tTable.Value)-1)AS [Values]FROM(SELECT t2.ID,(SELECT t1.Value + ':' AS [text()]FROM #TempTable t1Where t1.ID = t2.IDORDER BY t1.IDFor XML PATH ('')) [Value]FROM #TempTable t2) [tTable]
--Get the result by combining the two temp tables.SELECT DISTINCT(t2.ID), t1.Name, t2.Value FROM #TempTable2 t2, #TempTable t1WHERE t1.ID = t2.ID--Finally drop the temp tables.DROP TABLE #TempTableDROP TABLE #TempTable20Add a comment
Add a comment