Jump to content

_stringbetween (Someone find the obvious error)


floodge
 Share

Recommended Posts

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

<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

Link to comment
Share on other sites

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

<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

Link to comment
Share on other sites

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)
;=======================================================================
;
Link to comment
Share on other sites

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

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

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