我需要从星号分隔的数据中拆分一些信息。
数据格式:
NAME*ADRESS LINE1*ADDRESS LINE2
Run Code Online (Sandbox Code Playgroud)
规则:
1. Name should be always present
2. Address Line 1 and 2 might not be
3. There should be always three asterisks.
Run Code Online (Sandbox Code Playgroud)
样品:
MR JONES A ORTEGA*ADDRESS 1*ADDRESS2*
Name: MR JONES A ORTEGA
Address Line1: ADDRESS 1
Address Line2: ADDRESS 2
A PAUL*ADDR1**
Name: A PAUL
Address Line1: ADDR1
Address Line2: Not Given
Run Code Online (Sandbox Code Playgroud)
我的算法是:
1. Iterate through the characters in the line
2. Store all chars in a temp variables until first * is …Run Code Online (Sandbox Code Playgroud)