Jump to content

String replacement problems..


Azu
 Share

Recommended Posts

How it should work is, you put in some numbers in the input field, separated by spaces, and when you press Home it chooses one of them randomly and brings up a message saying which one it chose, and it should only do choose numbers. This part works.

When you press end, it should do pretty much the same thing, except it should remove whichever number it chose. If you put in the number 3 times it should remove all 3. If you put it in once it should remove that. However it should only remove it if it's an exactly match. Let's say the number is 1. It should remove exact matches of the number one. But if there is a number 10 or 100 or 210, it should not do anything to those numbers. If there is ever two spaces, they should be turned into a single space. If there is a space after the last number, it should be removed; or else there is going to be values in the code that equal "" E.G. a blank. I want those to be removed. Only numbers should be left. Letters and characters and anything except numbers higher then 0 should be removed. But if there is a 0 in another number like 103 or something, that 0 should be left alone.

This part isn't working.

I've tried for hours to get it to work but I just can't get it working.

Now the script won't even run it just errors out.

Please help! Thank you!

dim $ba[99]
global $rnd
global $ba1
hotkeyset("{home}","st")
hotkeyset("{end}","ex")

opt("guioneventmode",1)
$mygui=guicreate("x",160,115)
guisetstate()
$xlable=guictrlcreatelabel("x:",0,30,20,11)
$xinput=guictrlcreateinput("1",36,30,124,16)

func st()
$ba=stringsplit(guictrlread($xinput),' ',1)
do
$rnd=$ba[random(1,$ba[0],1)]
until $rnd<>"" and $rnd<>" " and $rnd>0
MsgBox(0,$ba[0],$rnd)
endfunc

func ex()
do
stringcreat()
until $ba[$ba[0]]<>"" and $ba[$ba[0]]<>" " and $ba[$ba[0]]>0
$rnd=$ba[random(1,$ba[0],1)]
if $rnd="" or $rnd=" " then ex()
guictrlsetdata($xinput,$ba1)
MsgBox(0,$ba[0],$rnd)
endfunc

while 1
sleep(99999)
wend

func stringcreat()
$ba1=""
for $a = 1 to $ba[0]
$ba=stringsplit($ba1,' ',1)
if $ba[$a]<>"" and $ba[$a]<>" " and $ba[$a]>0 and $ba[$a] then $ba1=$ba1&$ba[$a]
if $a<$ba[0] and $ba[$a]<>"" and $ba[$a]<>" " and $ba[$a]>0 and $ba[$a] then $ba1=$ba1&" "
next
$ba1=StringReplace($ba1,$rnd,"")
$ba1=StringReplace($ba1,"  "," ")
$ba=stringsplit($ba1,' ',1)
endfunc
Link to comment
Share on other sites

  • Developers

Func ex()
    $ba = StringSplit(GUICtrlRead($xinput), ' ', 1)
    Do
        $rnd = $ba[Random(1, $ba[0], 1) ]
    Until $rnd <> "" And $rnd > 0
    MsgBox(0, $ba[0], $rnd)
    $NewString = ""
    For $x = 1 To $ba[0]
        If $rnd <> $ba[$x] Then $NewString &= $ba[$x] & " "
    Next
    GUICtrlSetData($xinput, StringStripWS($NewString, 1))
EndFunc   ;==>ex

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thanks.

It's still putting an extra space at the end of it though, and as spaces are what I use to signify seperation of values, it makes the script think there is an extra value at the end there, although it's a blank.

For example

It's "1 2 3 4 5 6 8 9" to begin with

"2" is chosen, and removed, but it ends up with "1 3 4 5 6 8 9 "

Where as it should be "1 3 4 5 6 8 9"

Without an extra space at the end.

If I use commas or something else to seperate them, I end up with a comma at the end. So I'm sure it's not a problem caused by using spaces.

Any ideas on how I can fix this, please? :P

Link to comment
Share on other sites

  • Developers

Thanks.

It's still putting an extra space at the end of it though, and as spaces are what I use to signify seperation of values, it makes the script think there is an extra value at the end there, although it's a blank.

For example

It's "1 2 3 4 5 6 8 9" to begin with

"2" is chosen, and removed, but it ends up with "1 3 4 5 6 8 9 "

Where as it should be "1 3 4 5 6 8 9"

Without an extra space at the end.

If I use commas or something else to seperate them, I end up with a comma at the end. So I'm sure it's not a problem caused by using spaces.

Any ideas on how I can fix this, please? :nuke:

made a mistake in the StringStripWS()

should be StringStripWS($NewString, 2)

:P

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...