找回密码
 加入
搜索
查看: 2731|回复: 2

读取配置文件时,如何替换换行符为,回车?

[复制链接]
发表于 2008-6-28 15:01:12 | 显示全部楼层 |阅读模式
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("开机公告", 375, 269, 303, 219)
$Group9 = GUICtrlCreateGroup("开机公告", 3, 8, 369, 257)
$Edit1 = GUICtrlCreateEdit(IniRead ( "server.INI","网吧公告","提示内容","" ), 11, 24, 353, 201)
$Button1 = GUICtrlCreateButton("开启", 210, 232, 43, 25, 0)
$Button2 = GUICtrlCreateButton("禁止", 262, 232, 43, 25, 0)
$Button3 = GUICtrlCreateButton("设置", 313, 232, 43, 25, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
case $button1
IniWrite("SerVer.ini", "网吧公告", "是否运行", "1")
msgbox(64,"提示","设置成功")
case $button2
IniWrite("SerVer.ini", "网吧公告", "是否运行", "0")
msgbox(64,"提示","设置成功")
case $Button3
$post1 = StringReplace(GUICtrlRead($edit1), @CRLF, "@LF")
IniWrite("SerVer.ini", "网吧公告","提示内容", $post1)
msgbox(64,"提示","设置成功")
EndSwitch
WEnd
读取的问题解决了,
$Edit1 = GUICtrlCreateEdit(IniRead ( "server.INI","网吧公告","提示内容","" ), 11, 24, 353, 201)
写入时替换换行也解决了,
$post1 = StringReplace(GUICtrlRead($edit1), @CRLF, "@LF")

就剩读取的换行问题了。

以下是配置文件SERVER.INI
[网吧公告]
提示内容=本网吧收费:@LF        会员卡:1.5元/小时@LF        临时卡:2元/小时@LF        夜场卡:6元/23:00-09:00@LF  请小心保管自己的贵重物品,不要把手机放在台面上,提防@LF小偷!请自行保管自己的各种虚拟帐号,如有丢失网吧概不负@LF责!
是否运行=0
[ 本帖最后由 cj4025 于 2008-7-1 17:41 编辑 ]
发表于 2008-6-28 22:58:27 | 显示全部楼层

改好了

代码:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("开机公告", 375, 269, 303, 219)
$Group9 = GUICtrlCreateGroup("开机公告", 3, 8, 369, 257)
$Edit1 = GUICtrlCreateEdit(StringFormat(IniRead("server.INI", "网吧公告", "提示内容", "")), 11, 24, 353, 201)
$Button1 = GUICtrlCreateButton("开启", 210, 232, 43, 25, 0)
$Button2 = GUICtrlCreateButton("禁止", 262, 232, 43, 25, 0)
$Button3 = GUICtrlCreateButton("设置", 313, 232, 43, 25, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        IniWrite("SerVer.ini", "网吧公告", "是否运行", "1")
                        MsgBox(64, "提示", "设置成功")
                Case $Button2
                        IniWrite("SerVer.ini", "网吧公告", "是否运行", "0")
                        MsgBox(64, "提示", "设置成功")
                Case $Button3
                        $post1 = StringReplace(GUICtrlRead($Edit1), @CRLF, "\r\n")
                        IniWrite("SerVer.ini", "网吧公告", "提示内容", $post1)
                        MsgBox(64, "提示", "设置成功")
        EndSwitch
WEnd

配置文件 Server.ini:
[网吧公告]
提示内容=本网吧收费:\r\n        会员卡:1.5元/小时\r\n        临时卡:2元/小时\r\n        夜场卡:6元/23:00-09:00\r\n  请小心保管自己的贵重物品,不要把手机放在台面上,提防\r\n小偷!请自行保管自己的各种虚拟帐号,如有丢失网吧概不负\r\n责!\r\n\r\n                                            此致\r\n                                   敬礼!
\r\n


是否运行=0

注意,在“是否运行=0 ”上面至少要留一空行。

[ 本帖最后由 bigger 于 2008-6-28 23:08 编辑 ]
 楼主| 发表于 2008-7-1 17:41:22 | 显示全部楼层
谢谢,问题解决
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-7 04:45 , Processed in 0.072086 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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