Jump to content

[Solved] Stringsplit Q


goldenix
 Share

Recommended Posts

A question: Is there a function that can do this, or to meke my life a little easier, so I wont need to use those billions of loops to make this:

Say I have any string, for example: Roman Gaman Aijou Ban Or it can be bigger, contain more words

I want to put it into an array like this:

Roman Gaman
Gaman Aijou
Aijou Ban

Whats the best way to do this?

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]
Link to comment
Share on other sites

So you want to take a string with 2+ words separated by a single space and output all of the possible 2 word variations from it?

not all possible, only first & second, second & third, third & forth And so on.

So far I got this: But im little skeptical if this will work, cuz its kind of too simple code. :D

$split = stringsplit('1 2 3 4 5 6 7 8 9',' ')

    For $x = 1 to $split[0] -1

        ConsoleWrite($split[$x] & ' ' & $split[$x+1] & @CRLF)
    Next

    Exit

Edit: hmm yes I think it will work.

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]
Link to comment
Share on other sites

Well if that's all you want then that code seems like it should very well do the trick!

Is there a scenario where you're finding that isn't true?

Im not sure yet, this was simple example & only the first possible scenario. next ones will be more complicated, will contain different chars so splitting will be real pain.

But let me ask 1 more thing: how can you find a string between 2 characters or words?

like:[Terunyo Kusatsu] Pet Life [08-11-01]

I need this: An note that I must eliminate the numerical value & keep only text

Terunyo Kusatsu
Pet Life
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]
Link to comment
Share on other sites

$fileread = FileRead("path")

$array = StringSplit($fileread, " ", 2)

For $i = 0 To UBound($array) - 2
    FileWrite("path", $array[$i] & " " & $array[$i + 1] & @CRLF)
Next

Looks like I should have refreshed my page before posting :D

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

Im not sure yet, this was simple example & only the first possible scenario. next ones will be more complicated, will contain different chars so splitting will be real pain.

But let me ask 1 more thing: how can you find a string between 2 characters or words?

like:[Terunyo Kusatsu] Pet Life [08-11-01]

I need this: An note that I must eliminate the numerical value & keep only text

Terunyo Kusatsu
Pet Life

You'll want to take a look at StringRegExp. If you've never used stringregexp before, you should read neogia's tutorial.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

  • Moderators

This expression may work for the 2nd part:

"\[\s*(.+?)\s*\]\s*(.+?)\s*\[\d+-\d+-\d+\]"

#include <Array.au3>
Global $s_string = "[Terunyo Kusatsu] Pet Life [08-11-01]"
Global $s_pattern = "\[\s*(.+?)\s*\]\s*(.+?)\s*\[\d+-\d+-\d+\]"
Global $a_return = StringRegExp($s_string, $s_pattern, 3)
_ArrayDisplay($a_return)
Edited by SmOke_N
Didn't see you wanted both, fixed code

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

ooh thanx, it works, Now I go read the regexp tutorial so i can hopefully understand, why it works :D

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]
Link to comment
Share on other sites

One important point not mentioned in the tutorial.

"\" can be used to escape special characters, so "\[" doesn't search for "\" and whatever is in the set, it actually searches for "[".

Edit: why is it that I always notice the grammar errors after I click the post button?

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

and im forced to ask again. how do you display only text inside brackets or exclude the text?

Those above examples dont work, if the string looks little different.

And also I read the guide, And it does not explain how to do that. I tried to modify the sampe above, but I dont understand what im doing :D

So can you please explain also?

say ewe have any string: [desu] [08-11-01] Shigai - konta Pus (sfsg)

And you want to remove everything between [] so result will look like this: Shigai - konta Pus (sfsg)

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]
Link to comment
Share on other sites

Well, you could use a flag of 3 and this pattern (I think, haven't tested it)

"\[[a-z]\] \[\d+-\d+-\d+\] ([^\r]{1,})"

Note: since I used \r, it captures everything after the two sets of brackets until a carriage return, if whatever your using this on is formatted differently, you'll have to change it.

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

  • Moderators

and im forced to ask again. how do you display only text inside brackets or exclude the text?

Those above examples dont work, if the string looks little different.

And also I read the guide, And it does not explain how to do that. I tried to modify the sampe above, but I dont understand what im doing :D

So can you please explain also?

say ewe have any string: [desu] [08-11-01] Shigai - konta Pus (sfsg)

And you want to remove everything between [] so result will look like this: Shigai - konta Pus (sfsg)

String manipulation is a delicate thing when you're playing around like this.

You need to be VERY specific in what you need and what the rest of the layout/text would look like or be when asking for help.

( An example file and specifics of what you're trying to accomplish, along with code you yourself have tried is required )

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You need to be VERY specific in what you need and what the rest of the layout/text would look like or be when asking for help.

See, there is no spesific string, the brackets can include anything you can imagine.

For example it can even look like this: Its japanese.

(同人CG集) [地獄ポーション] イ・寺戦隊の桃色.lzh

But see, at this point i understand only as much as the guide explained.

If you could explain how to get rid of everything inside [] and () separately, I would have better understanding how its done & a sample in front of my eyes.

So im hoping for something like this:

$asResult = StringRegExpreplace('(ff456) [e(9843] [5435h.65"#%] some text', 'replace anything inside brackets with','')
$asResult = StringRegExpreplace($asResult , 'replace anything inside soft brackets with nothing',''
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]
Link to comment
Share on other sites

Replace everything inside [ ] : )

$string = "I [walked in the park. At around 4 ]am[. It was ] very [late at night. I think I was ]confused [why I was even there. It felt like a dream. I came across a man ]about [my height. He told me about a great thing called ]regexp[, but I didn't know what it was. Then I woke up]."

$data = StringRegExpReplace($string, "\[(.*?)\]", "")
MsgBox(0,"", $data)

The pattern to remove within () is this: \((.*?)\)

Link to comment
Share on other sites

Replace everything inside [ ] : )

According to the guide, if you put stuff, inside () you can make groups,then why doesnt it work?

$STRING = '[desu] [08-11-01] Shin - konta Plus(Kano)'
;~ $data = StringRegExpReplace($STRING, "(\[(.*?)\])(\((.*?)\))", "")
$data = StringRegExpReplace($STRING, "\[(.*?)\]\((.*?)\)", "")
MsgBox(0,"", $data)
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]
Link to comment
Share on other sites

That checks for [...](...) instead of [...] OR (...).

Use a pipe to say it should search for this or that:

$STRING = '[desu] [08-11-01] Shin - konta Plus(Kano)'
;~ $data = StringRegExpReplace($STRING, "(\[(.*?)\])(\((.*?)\))", "")
$data = StringRegExpReplace($STRING, "\[(.*?)\]|\((.*?)\)", "")
MsgBox(0,"", $data)

Works.

Link to comment
Share on other sites

According to the guide, if you put stuff, inside () you can make groups,then why doesnt it work?

The guide was just to teach the basics of stringregexp. Very useful and well done, yet it doesn't cover everything. You should read through the helpfile.

The reason $data = "" is because Manadar used StringRegExpReplace, and replaced everything in between [] or () with a blank string.

Edit: misread helpfile on stringregexpreplace

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

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...