Jump to content
Sign in to follow this  

Need help with string [SOLVED]

Recommended Posts


Im trying to write a script that will recognize an equation

$input = InputBox("","")
$array = Stringsplit($input, "x")

What I want to do this is to strip all the white spaces off of all of the variable arrays. I was going to do StringStripWs. But here is my problem, I dont know how many array variables there will be. Like for example, if I entered 2x + 3. Then there would be variables array[1] and array[2], array[1] contains "2" while array[2] contains " + 3". But if I entered 3x^2 + 2x + 3. Then there would be three arrays. So how can I get the number of arrays created with the Stringsplit so I could use StringStripWs to strip the white spaces off of all of my array varriables? I was thinking something like $array[$x] but Im still a newbie so can anyone help me?

Found it. The function I needed was Ubound() :)

$input = InputBox("","")
$array = Stringsplit($input, "x")
$x = Ubound($array)
For $i = 0 to $x - 1
    $array[$i] = Stringstripws($array[$i], 8)
MsgBox(0,"",$array[$x - 1])
Edited by Ultima2

Share this post

Link to post
Share on other sites

#include <Array.au3>

$string = '3x^2 + 2x + 3'

$array = StringSplit($string,' ',1); Remove spaces & split

_ArrayDisplay($array, "My Array")

MsgBox(4096,"Info", 'Array consists of ' & $array[0] & ' Rows')

For $r = 0 to UBound($array,1) - 1 
    MsgBox(4096,"$array[" & $r & ']', '_' & $array[$r] & '_                        ');I put alot of apaces hire so you could see the $array[$r]
    ConsoleWrite('_' & $array[$r] & '_' & @CRLF)

; Sample 2 you can remove spaces also like this:

$string = stringreplace($string,' ','') ; replace space with nothing

    ConsoleWrite($string & @CRLF)

Edit: ah ok just search help file for string & there are alot of functions + dont forget to check the user defined functions in the help file under String management

Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post

Link to post
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
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.