Jump to content
Sign in to follow this  
floodge

_stringbetween (Someone find the obvious error)

Recommended Posts

floodge

--------------------------------------------------------------

<Entry1>

<TS Value="1253666728883"/>

<T Value="nothing usable in this box lololollol"/>

<NT Value="541"/>

<NS Value="0"/>

<NC Value="196"/>

<NP3 Value="WBP"/>

<NP1 Value="Friendlyperson"/>

<TT Value="-1"/>

<PX Value="-1.0"/>

<PY Value="-1.0"/>

<PZ Value="-1.0"/>

</Entry1>

--------------------------------------------------------------

I have this above file and this code to grab from it

$file = FileOpen("tester.xml", 0)

$gui = FileRead($file)

$entry = _StringBetween($gui,'<Entry1> ','</Entry1>')

The problem is, $entry is ALWAYS equal to zero no matter what I tweak - It's pretty late but I have no idea why this is the case

Share this post


Link to post
Share on other sites
floodge

Here it is:

$entry = _StringBetween($gui,'<Entry1> ','</Entry1>')
; Right about . . . . . . . . . . . . ^ there

Nope, still fails just the same without that - in fact i added it to try and trick it into working

Share this post


Link to post
Share on other sites
99ojo

--------------------------------------------------------------

<Entry1>

<TS Value="1253666728883"/>

<T Value="nothing usable in this box lololollol"/>

<NT Value="541"/>

<NS Value="0"/>

<NC Value="196"/>

<NP3 Value="WBP"/>

<NP1 Value="Friendlyperson"/>

<TT Value="-1"/>

<PX Value="-1.0"/>

<PY Value="-1.0"/>

<PZ Value="-1.0"/>

</Entry1>

--------------------------------------------------------------

I have this above file and this code to grab from it

$file = FileOpen("tester.xml", 0)

$gui = FileRead($file)

$entry = _StringBetween($gui,'<Entry1> ','</Entry1>')

The problem is, $entry is ALWAYS equal to zero no matter what I tweak - It's pretty late but I have no idea why this is the case

Hi,

i'm having the same problem and didn't find a solution with _StringBetween.

If your xml file always look like above, i would do it like this:

$file = FileOpen("c:\temp\test.xml", 0)
$text = FileRead($file)
FileClose ($file)
$entry = StringTrimRight (StringTrimLeft ($text,9), 11)
MsgBox (0,"",$entry)

:D

Share this post


Link to post
Share on other sites
floodge

I knew it wasn't just me! :D

I'll try and substitute your alternate way

Share this post


Link to post
Share on other sites
Malkey

Here are a couple of ways.

;
;==== This way ========================================================
#include <string.au3>

$file = "test.xml"
$text = FileRead($file)
ConsoleWrite($text & @CRLF)
$entry = _StringBetween($text, "<Entry1>" & @CRLF, @CRLF & "</Entry1>")
MsgBox(0, "_StringBetween Result", $entry[0])
;=======================================================================

; Or this way
;=======================================================================
$text = FileRead("test.xml")
$entry = StringRegExpReplace($text, "(?:<Entry1>\v+)(?s)(.*?)(\v+</Entry1>)", "\1")
MsgBox(0, "StringRegExpReplace Result", $entry)
;=======================================================================
;

Share this post


Link to post
Share on other sites
99ojo

Here are a couple of ways.

;
;==== This way ========================================================
#include <string.au3>

$file = "test.xml"
$text = FileRead($file)
ConsoleWrite($text & @CRLF)
$entry = _StringBetween($text, "<Entry1>" & @CRLF, @CRLF & "</Entry1>")
MsgBox(0, "_StringBetween Result", $entry[0])
;=======================================================================

; Or this way
;=======================================================================
$text = FileRead("test.xml")
$entry = StringRegExpReplace($text, "(?:<Entry1>\v+)(?s)(.*?)(\v+</Entry1>)", "\1")
MsgBox(0, "StringRegExpReplace Result", $entry)
;=======================================================================
;

Hi,

thanks for opening eyes. I should have read helpfile better. Such a shame :D

Success: A 0 based $array[0] contains the first found string.

;-))

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites
jvanegmond

Nope, still fails just the same without that - in fact i added it to try and trick it into working

Please try the files I have attached. You'll find that the space was the error.

Share this post


Link to post
Share on other sites
99ojo

Please try the files I have attached. You'll find that the space was the error.

Hi,

i think he did the same mistake as me:

Msgbox (0,"",$entry) instead of

Msgbox (0,"",$entry [0])

;-))

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites
jvanegmond

No, displaying an array as string always returns "". He says $entry is equal to 0, which is not "", but instead is the error value as returned by _StringBetween. That's not his mistake.

Share this post


Link to post
Share on other sites
99ojo

Nope, still fails just the same without that - in fact i added it to try and trick it into working

@Manadar

Look at this answer from him, just after your tip with the blank.

So i think, he means "" and not 0.

But in fact, your right if $entry would be really zero, _StringBetween failed.

:-)))

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites
jvanegmond

There's really no point in arguing over what we interpreted what he said. He said the result was zero, he never said otherwise.

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  

×