Ticket #40464

strsplit use <TAB> separator key

Open Date: 2020-06-04 21:26 Last Update: 2020-06-06 12:44

Reporter:
Owner:
(None)
Status:
Open
Component:
MileStone:
(None)
Priority:
3
Severity:
3
Resolution:
None
File:
None
Vote
Score: 0
No votes
0.0% (0/0)
0.0% (0/0)

Details

When using strsplit function separator key is tab key

How to use LINE 2's groupmatchstr2 to get 1 and groupmatchstr3 to get 2

ex:
host.txt
192.168.1.1<tab>1<tab>2
192.168.1.2<tab><tab>1<tab>2

TTL file:
fileopen fhandle "C:\host.txt" 0
code2str tab_key $9
filereadln fhandle line
strsplit line tab_key

OUTPUT:
LINE 1
	groupmatchstr1=192.168.1.1	groupmatchstr2=1	groupmatchstr3=2
LINE 2
	groupmatchstr1=192.168.1.2	groupmatchstr2=empty	groupmatchstr3=1

Ticket History (3/3 Histories)

2020-06-04 21:26 Updated by: chenfou2001
  • New Ticket "strsplit use <TAB> separator key" created
2020-06-06 12:28 Updated by: nmaya
  • Details Updated
2020-06-06 12:44 Updated by: nmaya
Comment

"strsplit" macro command splits a string by "one delimiter character." https://ttssh2.osdn.jp/manual/4/en/macro/command/strsplit.html

If separated by <tab> character, 2nd part of line 2 is ""(empty string.) I think this behavior is not wrong.

To ignore empty column, check length of groupmatchstr2 variable, and skip it.

host = groupmatchstr1
strlen groupmatchstr2
if result > 0 then
  opt1 = groupmatchstr2
  opt2 = groupmatchstr3
else
  opt1 = groupmatchstr3
  opt2 = groupmatchstr4
endif

Attachment File List

No attachments

Edit

You are not logged in. I you are not logged in, your comment will be treated as an anonymous post. » Login