明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2330|回复: 2

[求助]TXT文件格式转换-字符串转表操作

[复制链接]
发表于 2010-8-20 10:53 | 显示全部楼层 |阅读模式

请教,有个明码文件格式如下:
0.00,847.40
10.76,856.00,17.48,861.20,25.19,868.90,27.50,871.20,30.29,871.50,34.98,878.10

我如何通过LISP所它换成如下格式:
0.00 847.40
10.76 856.00
17.48 861.20
25.19 868.90
27.50 871.20
30.29 871.50
34.98 878.10


直接用READ-LINE读取出来的是一行的字符串

发表于 2010-8-20 11:20 | 显示全部楼层

知道读取文件的流操作吗?基本原理就是一个字节一个字节的读取的,,,,

同样,read-line一行一行读取之后转成表形式,文本读完一行,进行表合并,再进行表两两拆分.

发表于 2010-8-20 12:46 | 显示全部楼层
  1. (defun c:tt (/ txt n1 a b)
  2.   (setq txt "0.00,847.40,10.76,856.00,17.48,861.20,25.19,868.90,27.50,871.20,30.29,871.50,34.98,878.10")
  3.   (command "pline")
  4.   (while (setq n1 (vl-string-search "," txt))
  5.     (setq a   (substr txt 1 (- n1 1))
  6.    txt (substr txt (+ n1 2))
  7.     )
  8.     (if (setq n2 (vl-string-search "," txt))
  9.       (setq b (substr txt 1 (- n2 1))
  10.      txt (substr txt (+ n2 2))
  11.       )
  12.       (setq b nil)
  13.     )
  14.     (if (and a b)
  15.       (command (list (distof a) (distof b)))
  16.     )
  17.   )
  18.   (command "")
  19.   (princ)
  20. )
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-14 01:30 , Processed in 0.168990 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表