Jump to content

Get text before certain character, and after?


Dracil
 Share

Recommended Posts

$days = StringSplit("Sun,Mon,Tue,Wed,Thu,Fri,Sat", ",")

;$days[1] contains "Sun" ... $days[7] contains "Sat"

flag = 1, entire delimiter string is needed to mark the split

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

soooo....

$days[3] = "$" & $days[3]

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

If $obj = "Hello $Me" or "Hello $Whatever" already, why does that string need to be StringSplit out of itself and set to something else? Why not just use $obj, again?

Edit: Does $obj always but only sometimes have "Hello"? If the string <> "Hello", or if it's more than 5 chars, or some other thing.., then put a StringSplit to it..

Edited by snowmaker

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

Oh, I thought you wanted the "$" back on after the stringsplit.

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

StringRegExp might be the easiest way then.

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

$obj changes it can be

$obj = "Hello $Me" 
$obj = "Hello $Doll"
 $obj = "Hello"

When its just "Hello" it crashes with stringsplit

Check if StringSplit was successful:

#include <array.au3> ; for _ArrayDisplay
$obj = "Hello $Me" 
$result = StringSplit($obj," ")
If @error Then  $result = $obj
If IsArray($result) Then
    _ArrayDisplay($result)
Else
    MsgBox(0,"",$result)
EndIf

Hi ;)

Link to comment
Share on other sites

Does this work in all cases the way you need?

#include <Array.au3>
Local $str[6] = ["Hello$World!", "Hello$", "Hello", "$World!", "$", ""], $ret
For $i = 0 To UBound($str) - 1
    $ret = StringRegExp($str[$i], "([^$]*)\$?([^$]*)?", 1)
    _ArrayDisplay($ret, "Split of '" & $str[$i] & "'")
Next

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)

Link to comment
Share on other sites

Ok that looks good so far,

so if its

$days = StringSplit("Hey man $aha"," {:content:}quot;)
MsgBox(0,"",$days[1]) MsgBox(0,"",$days[3])

It works, but the problem is it can end up without the " $")

$days = StringSplit("Hey girl", " $") 
MsgBox(0,"",$days[1]) MsgBox(0,"",$days[3])

And that wont let me run it.

For future reference, I direct your attention to the parameters of StringSplit in the help file.

You are using "0", the default flag parameter, which is wrong, because you are using more than one character as the delimiter to mark the split/s in the string.

#include <Array.au3>
$days = StringSplit("Hey man $aha", " $", 3)
_ArrayDisplay($days)

Edit: Change the the automatic change of " $" to " {:content:}quot; back to " $"

Edit2: And again.

Edited by Malkey
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...