Lyee

[SOLVED] Convert string into more strings?

15 posts in this topic

#1 ·  Posted (edited)

Hello,

I'm currently doin with numbers in notepad and when function FileReadLine read the line in Notepad I'm having the line with numbers (variable $line) but I have lot of numbers there and I need just 10~~:

206779,-10,4,2,0,60,0,0,D|256:284,192:256,1,144,4|0,0:0|0:0,0:0:0:0:

How to define each number to variables after ',' and skip a certain number of '|' symbols..

Or I acutally can just define that line and then call numbers but I dont know how to do it. It's hard af. Can someoen help me? Thank you :/

Edited by Lyee

Share this post


Link to post
Share on other sites



#2 ·  Posted

Please tell us which values you expect to obtain from processing the line in the example given. That would make it much easier to help you.

 


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

These: 206779,-10,4,2,0,60,0,0,D|256:284,192:256
From: 206779,-10,4,2,0,60,0,0,D|256:284,192:256,1,144,4|0,0:0|0:0,0:0:0:0:

D|256:284, 192:256 convert to D,256, 284, 192, 256 so actually skip ':' and '|' symbols and replace with ',' so it actually can be possible with stringreplace func. D letter is most wanted too

 

Edited by Lyee

Share this post


Link to post
Share on other sites

#4 ·  Posted

If I understand your text, you just whish to replace columns and bars by commas. But this is not what I see in the "These" line.

Please clarify.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#5 ·  Posted

fuu..

I need these numbers define as variables and call them from another function

206779,-10,4,2,0,60,0,0,D|256:284,192:256
X
$num1, $num2, $num3, $num4, $num.....

($num1 = 206779)
($num2 = -10)
...
..
.

btw Sorry for my bad eng Im not enough good speaker

Share this post


Link to post
Share on other sites

#6 ·  Posted

You can extract all numbers like this:

$line = "206779,-10,4,2,0,60,0,0,D|256:284,192:256,1,144,4|0,0:0|0:0,0:0:0:0:"
$aValues = StringRegExp($line, "-?\d+", 3)
_ArrayDisplay($aValues)

Then access values like this: $aValues[0], $aValues[1], $aValues[2], $aValues[3], ...


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#7 ·  Posted

Thats what I wanted.. Thank you a lot

Share this post


Link to post
Share on other sites

#8 ·  Posted

one more thing yet.. How can I see how much variables in $aValues I'm having?

Share this post


Link to post
Share on other sites

#9 ·  Posted

UBound($aValues) will tell you that.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#10 ·  Posted

Lyee,

The Ubounds value of the array will give you the number of elements...

local $numElements = ubound($aValues) - 1

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#11 ·  Posted

Oops!!...Hi JCHD...


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#12 ·  Posted

Remove the -1 since we look for the number of elements, not the index of the last one.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#13 ·  Posted

@jchd - of course, thanks...

@Lyee - a small example of accessing the array...

#include <array.au3>

$line = "206779,-10,4,2,0,60,0,0,D|256:284,192:256,1,144,4|0,0:0|0:0,0:0:0:0:"

$aValues = StringRegExp($line, "-?\d+", 3)
_ArrayDisplay($aValues)

ConsoleWrite('The number of elements = ' & UBound($aValues) & @CRLF & 'The value of each is:' & @CRLF)

For $i = 0 To UBound($aValues) - 1
    ConsoleWrite(@TAB & 'Element # ' & $i + 1 & ' at offset ' & $i & ' = ' & $aValues[$i] & @CRLF)
Next

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#14 ·  Posted

you could also just assign them (cool kids can do it in the regex, I take an extra loop)

$line = "206779,-10,4,2,0,60,0,0,D|256:284,192:256,1,144,4|0,0:0|0:0,0:0:0:0:"

$aValues = StringRegExp($line, "-?\d+", 3)

For $i = 0 To UBound($aValues) - 1
assign("num" & $i , $aValues[$i])
Next

consolewrite(eval("num0")& @CR)
consolewrite(eval("num3")& @CR)
consolewrite(eval("num5"))

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#15 ·  Posted

Thank you guys, you helped me a lot <3

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