请教高手下-------数组分割重组问题
所属分类:  电脑问答 >>  编程

内容摘自网络,仅供参考,如有问题可与本站联系


问题描述:

我想把含有空格的文字前后调换...请问用数组怎么解决..比如:"我爱中国 中国是我家" 我要改为:"中国是我家 我爱中国" 意思就是空格前后互换顺序颠倒..注意请先判断文字中间是否有空格,还有三个空间的情况..

参考答案:

这个问题是这样应付的可以说大部份语言都有函数把 “我爱中国 中国是我家”按空白割开成数列我用AUTOIT来做,就在这里$sp=StringSplit($resultstring , " " ,1 )这时 $sp[1], $sp[2]。。。就是分开了的句子可以作出任何字串组合显示。请下这个东西玩玩http://www.geocities.com/ystsangnbs/testSplit.zipAUTOIT的源码:#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6#include <GUIListBox.au3>#include <GuiConstantsEx.au3>#include <WindowsConstants.au3>#include <Constants.au3>$pos=1$msg=""Opt('MustDeclareVars', 1)$Debug_LB = False ; _Main()Func _Main()Local $hListBoxlocal $AddEve1local $AddEve2local $AddEve3local $resultstringlocal $splocal $Del; Create GUIGUICreate("测试", 300, 200)$hListBox = GUICtrlCreateList("", 20, 60, 250, 90)$AddEve1 = GUICtrlCreateButton("这是第三部位头句", 5, 25, 95, 25, 0)$AddEve2 = GUICtrlCreateButton("中国是我家头句", 100, 25, 90, 25, 0)$AddEve3 = GUICtrlCreateButton("我爱中国头句", 190, 25, 90, 25, 0)$Del = GUICtrlCreateButton("清除", 190, 175, 90, 25, 0)_GUICtrlListBox_AddString($hListBox, "我爱中国 中国是我家 这是第三部位") GUISetState()$resultstring=_GUICtrlListBox_GetText($hListBox, 0)$sp=StringSplit($resultstring , " " ,1 )While 1 $msg = GUIGetMsg() If $msg = $AddEve1 Then _GUICtrlListBox_InsertString($hListBox,$sp[3] & " " & $sp[2] & " " & $sp[1] ,$pos)$pos=$pos+1endifIf $msg = $AddEve2 Then _GUICtrlListBox_InsertString($hListBox,$sp[2] & " " & $sp[3] & " " & $sp[1] ,$pos)$pos=$pos+1endifIf $msg = $AddEve3 Then _GUICtrlListBox_InsertString($hListBox,$sp[1] & " " & $sp[3] & " " & $sp[2] ,$pos)$pos=$pos+1endifIf $msg = $Del Then _GUICtrlListBox_DeleteString($hListBox, $pos-1)$pos=$pos-1endifif $msg=$GUI_EVENT_CLOSE then ExitLoopendif wendGUIDelete()EndFunc ;==>_Main

更多答案:

如果对回答不满意,可以 或是到 极品软件论坛 发贴求助。

相关问答
搜索电脑问答
名称: