SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    407
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Manipulate string

    Manipulate string

    Hi all.

    This is my initial email string in MySQL:
    chevymark.sunderland@9651.com

    I try this query:
    Code:
    mysql> SELECT
    	REPLACE (
    		SUBSTRING_INDEX(
    			'chevymark.sunderland@9651.com',
    			'@',
    			1
    		),
    		'.',
    		' '
    	) AS output;
    +----------------------+
    | output               |
    +----------------------+
    | chevymark sunderland |
    +----------------------+
    1 row in set
    Now I need this other output:
    Code:
    +---------+
    | output  |
    +---------+
    | chv snd |
    +---------+
    would be to say the first three consonants of the name and first three consonants of the surname.
    alternatively three random characters from the name and surname...

    I try this query but the output is wrong:
    Code:
     
    mysql> SELECT
    	CONCAT(
    		LEFT (
    			REPLACE (
    				SUBSTRING_INDEX(
    					'chevymark.sunderland@9651.com',
    					'@',
    					1
    				),
    				'.',
    				' '
    			),
    			3
    		),
    		' ',
    		(
    			LEFT (
    				REPLACE (
    					SUBSTRING_INDEX(
    						SUBSTRING_INDEX(
    							'chevymark.sunderland@9651.com',
    							'@',
    							1
    						),
    						'.',
    						' '
    					),
    					' ',
    					- 1
    				),
    				3
    			)
    		)
    	) AS output;
    +--------+
    | output |
    +--------+
    | che    |
    +--------+
    1 row in set
    how can i do it?
    any help?
    thank you.

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,178
    Mentioned
    63 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by cms9651 View Post
    would be to say the first three consonants of the name and first three consonants of the surname.
    alternatively three random characters from the name and surname...
    What happens if the user doesn't even have 3 characters in one of their names?

  3. #3
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    407
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by K. Wolfe View Post
    What happens if the user doesn't even have 3 characters in one of their names?
    I don't have any of these cases
    Thanks you very much for your help
    I'm really happy for your quickly answer.
    Good bye

  4. #4
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,178
    Mentioned
    63 Post(s)
    Tagged
    2 Thread(s)
    I believe your going to have to use a server side function in order to accomplish this (PHP / ASP).

    Using PHP, I would use str_split() and iterate through until you have your result.

  5. #5
    SitePoint Evangelist cms9651's Avatar
    Join Date
    Mar 2010
    Posts
    407
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by K. Wolfe View Post
    I believe your going to have to use a server side function in order to accomplish this (PHP / ASP).

    Using PHP, I would use str_split() and iterate through until you have your result.
    thank you for help.
    My language servers side is ASP NET and this the solution (Linq to filter):
    Code:
            string vowels = "aeiouy";
            string name = "chevymark.sunderland@9651.com";
            name = new string(name.Where(c => !vowels.Contains(c)).ToArray());
            string[] strresult = name.Split('.');
            string stroutput = strresult[0].Substring(0,3) + " " + strresult[1].Substring(0,3);
    Thanks you very much for your help
    I'm really happy for your quickly answer.
    Good bye


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •