Scenario:
I have a record like this:
field1 = "id='102',name='yty,wskjd',city='eytw' "
Note: sometimes data might come as [id,name, city] or sometimes it might come as [code,name,id]. It varies...
I need to store the value of field1 into different fields,
value1 = id='102'
value2 = name='yty,wskjd'
value3 = city='eytw'
If I split the record based on comma(,) then the result wont come as expected as there is a comma(,) in value of name.
Is there a way where we can achieve the solution in easier way i.e., if a comma comes in between two single quotes then we have to suppress the comma(,). I gave a try with different inbuilt functions but couldnt make it. Is there a way to read the data in between 2 single quotes ???
field1 = "id='102',name='yty,wskjd',city='eytw' "
Note: sometimes data might come as [id,name, city] or sometimes it might come as [code,name,id]. It varies...
I need to store the value of field1 into different fields,
value1 = id='102'
value2 = name='yty,wskjd'
value3 = city='eytw'
If I split the record based on comma(,) then the result wont come as expected as there is a comma(,) in value of name.
Is there a way where we can achieve the solution in easier way i.e., if a comma comes in between two single quotes then we have to suppress the comma(,). I gave a try with different inbuilt functions but couldnt make it. Is there a way to read the data in between 2 single quotes ???
Solution:
Please try below solution it may help u in some extent
Field1 = "id='102',name='yty,wskjd',city='eytw' "
Steps -
1. v_1 = Replace(field1, '"' , '') --i.e. no space
2. v_2 = substring-after ( v_1, id= ) --O/P '102',name='yty,wskjd',city='eytw'
3. v_3 = substring-after ( v_1, name= ) --O/P 'yty,wskjd',city='eytw'
4. v_4 = substring-after ( v_1, city= ) --O/P 'eytw'
5. v_5 = substring-before(v_2, name) --O/P '102',
6. v_6 = substring-before ( v_3, city ) --O/P 'yty,wskjd',
7. value1 = replace(v_5,',','') --O/P '102'
8. value3 = replace(v_6,',','') --O/P 'yty,wskjd'
7. value3 = v_4 --O/P 'eytw'
Comments
Post a Comment