Eigensheep Posted August 27, 2008 Share Posted August 27, 2008 Does anyone know of the best way to remove the last line in an edit control? I mean, if a user inputs: Line 1 Line 2 Line 3 How do you remove "line 3" so the control only displays the first 2? I have tried using StringInStr with StringMid and StringRight, just wondering if there is an easier way than going through every line? Link to comment Share on other sites More sharing options...
Andreik Posted August 27, 2008 Share Posted August 27, 2008 Does anyone know of the best way to remove the last line in an edit control? I mean, if a user inputs: Line 1 Line 2 Line 3 How do you remove "line 3" so the control only displays the first 2? I have tried using StringInStr with StringMid and StringRight, just wondering if there is an easier way than going through every line? I write a simple example to do what you want: $GUI = GUICreate("TEST",200,170) $EDIT = GUICtrlCreateEdit("LINE1" & @CRLF & "LINE2" & @CRLF & "LINE3",5,5,190,100) $REMOVE = GUICtrlCreateButton("REMOVE LAST LINE",5,120,190,40) GUISetState() While 1 $MSG = GUIGetMsg() If $MSG = $REMOVE Then $TEMP_DATA = GUICtrlRead($EDIT) $TEMP_DATA = StringSplit($TEMP_DATA,@CRLF) $NEW_DATA = "" For $INDEX = 1 To $TEMP_DATA[0]-1 Step 2 If $INDEX = $TEMP_DATA[0]-2 Then $NEW_DATA &= $TEMP_DATA[$INDEX] Else $NEW_DATA &= $TEMP_DATA[$INDEX] & @CRLF EndIf Next GUICtrlSetData($EDIT,$NEW_DATA) ElseIf $MSG = -3 Then Exit EndIf WEnd When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Eigensheep Posted August 27, 2008 Author Share Posted August 27, 2008 Thanks! Link to comment Share on other sites More sharing options...
Eigensheep Posted August 27, 2008 Author Share Posted August 27, 2008 I found a shorter way: $TEMP_DATA = GUICtrlRead($EDIT) $TEMP_DATA = StringSplit($TEMP_DATA,@CRLF) $NEW_DATA = StringReplace(GUICtrlRead($EDIT),$TEMP_DATA[$TEMP_DATA[0]-2] & @CRLF,"") GUICtrlSetData($EDIT,$NEW_DATA) Thanks for the reply anyway - it helped. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now