String将其值设置为" False"

时间:2016-05-06 08:41:09

标签: vb.net string

所以,我目前正在研究一个应该为Unitale-Engine创建Lua-Scripts的程序。我添加了一个"新项目"单击它时应创建新项目文件的按钮。我希望此文件包含默认的项目文件文本。所以我这样做了:

Dim File1 As String = "monster{" & vbNewLine & "COMMENTS=Ribbit, ribbit.;Croak, croak.;Hop, hop.;Meow." & vbNewLine & "COMMANDS=Compliment;Threaten" & vbNewLine & "DEFAULT_SPRITE=None" & vbNewLine & "NAME=Froggit" & vbNewLine & "HP=10" & vbNewLine & "ATK=1" & vbNewLine = "DEF=0" & vbNewLine & "CHECK_MESSAGE=Life is difficult for this enemy." & vbNewLine & "HandleAttack=" & vbNewLine & "OnDeath=" & vbNewLine & "HandleCustomCommand=" & vbNewLine & "}"
Dim File2 As String = vbNewLine & "encounter{" & vbNewLine & "DEFAULT_MUSIC=Fight" & vbNewLine & "ENCOUNTER_TEXT=Froggit hops close." & vbNewLine & "NEXTWAVES=1" & vbNewLine & "WAVETIMER=6" & vbNewLine & "ARENASIZE=155;130" & vbNewLine & "ENEMIES=Froggit" & vbNewLine & "ENEMYPOSITIONS=0;0" & "EncounterStarting=" & vbNewLine & "EnemyDialogueStarting=" & vbNewLine & "EnemyDialogueEnding=" & vbNewLine & "DefenseEnding=" & vbNewLine & "HandleItem=" & vbNewLine & "HandleSpare=" & vbNewLine & "EnteringState=" & vbNewLine & "Update=" & vbNewLine & "}"
Dim File3 As String = vbNewLine & "waves{" & vbNewLine & "1=Do Nothing" & vbNewLine & "}" & vbNewLine & "end"
My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\UnitaleMaker\Projects\" & PJNBox.Text & ".umproj", File1 & File2 & File3, False)

是的,那是很多文字。问题是,File1在声明时始终将其值设置为"False"。我认为这是因为字符串太长,所以我把它分成3个部分,但它不起作用。

任何帮助都会受到关注!

~Mika // OneByte _

2 个答案:

答案 0 :(得分:1)

VB 14 (Visual Studio 2015)开始,您可以跨多行跨越字符串文字。 VB 14还添加了字符串插值,这使代码更加清晰。您可以像下面那样编写代码,这样可以避免错误地使用& vbNewLine = "DEF=0" &并使代码更容易阅读。

我还假设您忘记了"ENEMYPOSITIONS=0;0" & "EncounterStarting="中的换行符,并且我在{}之间缩进了部分。我将File1File2File3合并为一个字符串,因为您声明在问题中将它们分开了,我假设您宁愿将其全部放在一个字符串中。< / p>

Dim File1 As String = "monster{
    COMMENTS = Ribbit, ribbit.;Croak, croak.;Hop, hop.;Meow.
    COMMANDS=Compliment;Threaten
    DEFAULT_SPRITE=None
    NAME=Froggit
    HP=10
    ATK=1
    DEF=0
    CHECK_MESSAGE=Life Is difficult For this enemy.
    HandleAttack=
    OnDeath=
    HandleCustomCommand=
}
encounter{
    DEFAULT_MUSIC = Fight
    ENCOUNTER_TEXT =Froggit hops close.
    NEXTWAVES=1
    WAVETIMER=6
    ARENASIZE=155;130
    ENEMIES=Froggit
    ENEMYPOSITIONS=0;0
    EncounterStarting=
    EnemyDialogueStarting=
    EnemyDialogueEnding=
    DefenseEnding=
    HandleItem=
    HandleSpare=
    EnteringState=
    Update=
}
waves{
    1 =Do Nothing
}
End"
My.Computer.FileSystem.WriteAllText($"{My.Computer.FileSystem.SpecialDirectories.MyDocuments}\UnitaleMaker\Projects\{PJNBox.Text}.umproj", File1, False)

答案 1 :(得分:0)

请学会使用string.format

我还在&中将new line更改为file2

"ENEMYPOSITIONS=0;0" & "EncounterStarting="

我只是假设你忘记在那里添加新行。

Alss Environment.NewLine是新线路的最佳选择,因为它是通用的。

Dim File1 As String = String.Format("monster{{{0}COMMENTS=Ribbit, ribbit.;Croak, croak.;Hop, hop.;Meow.{0}COMMANDS=Compliment;Threaten{0}DEFAULT_SPRITE=None{0}NAME=Froggit{0}HP=10{0}ATK=1{0}DEF=0{0}CHECK_MESSAGE=Life is difficult for this enemy.{0}HandleAttack={0}OnDeath={0}HandleCustomCommand={0}}}", Environment.NewLine)
    Dim File2 As String = String.Format("{0}encounter{{{0}DEFAULT_MUSIC=Fight{0}ENCOUNTER_TEXT=Froggit hops close.{0}NEXTWAVES=1{0}WAVETIMER=6{0}ARENASIZE=155;130{0}ENEMIES=Froggit{0}ENEMYPOSITIONS=0;0{0}EncounterStarting={0}EnemyDialogueStarting={0}EnemyDialogueEnding={0}DefenseEnding={0}HandleItem={0}HandleSpare={0}EnteringState={0}Update={0}}}", Environment.NewLine)
    Dim File3 As String =  String.Format("{0}waves{{{0}1=Do Nothing{0}}}{0}end", Environment.NewLine)
    My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\UnitaleMaker\Projects\" & PJNBox.Text & ".umproj", File1 & File2 & File3, False)