Split text by symbol
Jump to navigation
Jump to search
Split text by symbol (delimiter / separator)
Approachs
- Excel: (1) LEFT, RIGHT, FIND, LEN (2) MOD, FIND, LEN
- PHP: explode
- MySQL: MySQL SUBSTRING_INDEX() function - w3resource
Example
Task: Split 25.040215, 121.512532 by the comma ( , )
Expected output:
- 25.040215
- 121.512532
MySQL Approach
- How to get the first string ( 25.040215 ):
SELECT TRIM(SUBSTRING_INDEX('25.040215, 121.512532' ,',', 1)) - How to get the second string ( 121.512532 ):
SELECT TRIM(SUBSTRING_INDEX('25.040215, 121.512532' ,',', -1))