Jump to content

Problem with " " char in WriteFile


Recommended Posts

Hi Guys, i hope my topic was not against rules! :mellow:

Func Server1()
    $Server1 = IniRead("Server.ini","Server","Server 1","4.2.2.4")

    $Server = "<?xml version=""1.0"" encoding=""UTF-8"" ?>" & @CRLF
    $Server &= "<servers>" & @CRLF
    $Server &= "<cur>Server 1</cur>" & @CRLF
    $Server &= "<server name=""Sever 1"" ip=" & $Server1 & " rate=""25""/>" & @CRLF
    $Server &= "</servers>"

    FileWrite("Server.xml", $Server)
EndFunc

It's my code, as you can see i just read some variable from an existing .ini file using IniRead, and then i'm trying to make some kind of text generator (It's .xml).

everything is ok but the only problem i have is in the final XML file " " is missed just where i write my variable.

what it give:

<server name="Serever 1" ip=4.2.2.4 rate="25"/>

what i need:

<server name="Server 1" ip="4.2.2.4" rate="25"/>

Link to comment
Share on other sites

Guys i think i found it, btw is there any better way?

i did this and my code is working:

Func Server1()
    $Server1 = IniRead("Server.ini","Server","Server 1","4.2.2.4")

    $Server = "<?xml version=""1.0"" encoding=""UTF-8"" ?>" & @CRLF
    $Server &= "<servers>" & @CRLF
    $Server &= "<cur>Server 1</cur>" & @CRLF
    $Server &= "<server name=""Sever 1"" ip=" & '"' & $Server1 & '"' & " rate=""25""/>" & @CRLF
    $Server &= "</servers>"

    FileWrite("Server.xml", $Server)
EndFunc
Edited by D4RKON3
Link to comment
Share on other sites

hi D4RKON3,

Your topic is fine :)

There is no need to mix single and double quotes to achieve this, you were so close to the solution! :mellow:

$Server &= "<server name=""Server 1"" ip=" & $Server1 & " rate=""25""/>" & @CRLF
The concatenation seems to have confused you, you successfully encapsulated the name by doubling up on the double quotes, but you faltered at the IP.

Lets do it in steps, 1st with no variable IP:

$Server &= "<server name=""Server 1"" ip=""0.0.0.0"" rate=""25""/>" & @CRLF
This should put the quotes around the IP as you wanted.

Now if you wanted to put a variable between server and name you would do this right?

$Server &= "<server " & $variable & "name=""Server 1"" ip=""0.0.0.0"" rate=""25""/>" & @CRLF

So to replace 0.0.0.0 with a variable, replace 0.0.0.0 with " & $variable & " right? This gives:

$Server &= "<server name=""Server 1"" ip=""" & $Server1 & """ rate=""25""/>" & @CRLF

Simple right?

Hope this clears some things up :)

-smartee

Link to comment
Share on other sites

$Server &= "<server name=""Server 1"" ip=""" & $Server1 & """ rate=""25""/>" & @CRLF

$Server &= '<server name="Sever 1" ip="' & $Server1 & '" rate="25"/>' & @CRLF

you mean ' instead of " or im missing the point?

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

@bogQ,

The op wanted the output to look like this:

<server name="Server 1" ip="0.0.0.0" rate="25"/>

To achieve that he tried this:

$Server &= "<server name=""Server 1"" ip=" & $Server1 & " rate=""25""/>" & @CRLF
instead of this:
$Server &= "<server name=""Server 1"" ip=""" & $Server1 & """ rate=""25""/>" & @CRLF
then maybe he was frustrated with double quotes so he did this:
$Server &= "<server name=""Server 1"" ip=" & '"' & $Server1 & '"' & " rate=""25""/>" & @CRLF

I was just showing how he could've done it using double quotes alone, as that seemed to be his original plan :mellow:

Link to comment
Share on other sites

@bogQ,

The op wanted the output to look like this:

<server name="Server 1" ip="0.0.0.0" rate="25"/>

To achieve that he tried this:

$Server &= "<server name=""Server 1"" ip=" & $Server1 & " rate=""25""/>" & @CRLF
instead of this:
$Server &= "<server name=""Server 1"" ip=""" & $Server1 & """ rate=""25""/>" & @CRLF
then maybe he was frustrated with double quotes so he did this:
$Server &= "<server name=""Server 1"" ip=" & '"' & $Server1 & '"' & " rate=""25""/>" & @CRLF

I was just showing how he could've done it using double quotes alone, as that seemed to be his original plan :)

Exactly what i was searching for, tnx so much and it's done. :mellow:
Link to comment
Share on other sites

ouh, ok i see, ty smartee , so i did miss the point after all ^^

but still think that

$Server &= '<server name="Sever 1" ip="' & $Server1 & '" rate="25"/>' & @CRLF

its easyer than

$Server &= "<server name=""Server 1"" ip=""" & $Server1 & """ rate=""25""/>" & @CRLF

newer the less the results are identical so what ever is easyer for him to understand is the best choice for him :mellow:

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

Try:

$Server &= "<server name=" & chr(34) & "Sever 1" & chr(34) & " ip=" & chr(34) & "" & $Server1 & " & chr(34) & "rate=" & chr(34) & "25" & chr(34) & "/>" & @CRLF

If you want write " to file always use function

chr(34)
Edited by H4CK3D
Link to comment
Share on other sites

I found quad quotes ("""") work for me:

$Server &= "<server name=""Sever 1"" ip=" & $Server1 & " rate=""25""/>" & @CRLF

becomes:

$Server &= "<server name=" & """" & "Sever 1" & """" & " ip=" & $Server1 & " rate=" & """" & "25" & """" & "/>" & @CRLF

I'll have to look into the previous posts on how to wrap quotes around variables to see how that works.

Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007

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