任务单 #40464

strsplit use <TAB> separator key

开放日期: 2020-06-04 21:26 最后更新: 2020-06-06 12:44

报告人:
属主:
(无)
类型:
状态:
开启
组件:
里程碑:
(无)
优先:
3
严重性:
3
处理结果:
文件:
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

任务单历史 (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
评论

"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

编辑

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