Thursday, February 27, 2020

Regular Expressions: Remove Whitespace from Start and End

let hello = "   Hello, World!  ";
let wsRegex = /^\s+|\s+$/g; // Change this line
let result = hello.replace(wsRegex,""); // Change this line


Explanation :(/^\s+|\s+$/g;)

  1. caret symbol ^ looks at the start of string
  2. dollar symbol $ looks at the end of string
  3. The | is an OR operator
  4. \s+ looks for one or more white spaces 
  5. The g flag is needed to match all the spaces that are at the beginning OR at the end. Otherwise it would match only the first part of the regex, and the second part only if the first part doesn’t match anything



Wednesday, February 26, 2020

To Get Current Database Name in SQL SERVER


SELECT statement where I get the name of the current Database


SELECT DB_NAME() AS DataBaseName



Wednesday, February 19, 2020

How do I replace multiple spaces with a single space in C#?

Example:

1 2 3  4    5
would be:

1 2 3 4 5


Solution:-
RegexOptions options = RegexOptions.None;
Regex regex = new Regex("[ ]{2,}", options);     
tempo = regex.Replace(tempo, " ");


myString = Regex.Replace(myString, @"\s+", " ");

Friday, February 14, 2020

TRIM() In SQL Server 2017


SELECT TRIM('     My test query     ')

/* Result */
My test query


SELECT TRIM( '.! ' FROM  '@     My Test Query   !..') AS Result;

/* Result */
@     My Test Query


SELECT len(TRIM( '.! ' FROM  '@     My Test Query   !..')) AS Result;

/* Result */
19


SELECT firstName, TRIM(char(32) FROM firstName) as Trim_name from Table

Firstname  TrimName
      Test      Test

'CONCAT' is not a recognized built-in function name

"CONCAT" was introduced in SQL Server 2012; there is no way to make it work in SQL Server 2008 R2.


use the ODBC CONCAT function like this:

SELECT {fn CONCAT('foo ', 'test') }

The problem with this is that this function only allows you two parameters at a time. So unless you want to use more than two like this:

SELECT {fn CONCAT('foo ', {fn CONCAT('test ', 'buddy')}) }

 just use the '+' operator.

Syntax:

 select

 RTRIM(LTRIM(
        CONCAT(
COALESCE(c.Prefix + ' ', '')
           , COALESCE(c.FirstName + ' ', '')
            , COALESCE(c.MiddleName + ' ', '')
, COALESCE(c.LastName + ' ', '')
            , COALESCE(c.Suffix,+ ' ', '')
        )
    )) as CustomerName  from TableName


-- To Check SQL Server  version

--SELECT @@VERSION;
-- Microsoft SQL Server 2017 

Wednesday, February 12, 2020

Cache VS Session VS cookies?

State management is a critical thing to master when coming to Web world from a desktop application perspective.


  • Session is used to store per-user information for the current Web session on the server. It supports using a database server as the back-end store.
  • Cookie should be used to store per-user information for the current Web session or persistent information on the client, therefore client has control over the contents of a cookie.
  • Cache object is shared between users in a single application. Its primary purpose is to cache data from a data store and should not be used as a primary storage. It supports automatic invalidation features.
  • Application object is shared between users to store application-wide state and should be used accordingly.

Mixed Content: The page at xxx was loaded over HTTPS, but requested an insecure

 Mixed Content: The page at ' https ://www.test.com/signup.aspx' was loaded over HTTPS, but requested an insecure script ' http ...