Yukina0671 2019-01-25 22:06 采纳率: 50%
浏览 539
已采纳

VB.net 关于读取文章关键字的问题

最近和小伙伴一起想要做文字游戏,类似于《恋与制作人》那种的。以前从来没有试过读档之类的,在这个地方希望哪位大神能解答一下。
设想了一下一个关卡的文件大概是这样的:

#Description#
Tag:关卡号(Int)
Type:关卡类型(1:故事(此时无evaluation,battle项) 2:对战(此时无text项))
RewardTag:获得的物品编号
Rarity:获得该物品的概率
#End description#

#Text#
@1
Background:背景相对地址
Bubble:展示气泡类型(1:对话; 2:内心想法; 3:惊叹;缺省:跳过word参数)
Word:人物对话
@2
……
#End Text#

#Battle#
Event:(1:有选择题;2:无选择题)
@1
Title:选择题
Choices:选项数量(缺省为3;限制为2-3)
Choice1:选项1
Choice2:选项2
Choice3:选项3
Score1:选该选项得分
IconDisplay1:选该选项展示的msgbox类型(缺省,vbInformation,vbcritical)
Comment1:选该选项提示词
Score2:
IconDisplay1:
Comment1:
Score3:
IconDisplay1:
Comment1:
……
PowerModule1:需要的能力
PowerModule2:需要的能力
DomainModule1:能力1在最后分数中所占权重(1-100)
DomainModule2:能力2在最后分数中所占权重,缺省时为(100-DomainModule1)
#End Battle#

#Evaluation#
Target:1星分数
Good:2星分数
Perfect:3星分数
#End Evaluation#

读取了一下:

Dim ans As Integer
    Private Function GiveBackStageText(ByVal Filename As String)
        Dim lines() As String = IO.File.ReadAllLines(Application.StartupPath & "\" & Filename, System.Text.Encoding.Default).ToArray()
        Dim i As Integer
        Dim SearchString As String
        Dim SearchChar As String = "#Text#"
        Dim Index As Integer
        For i = 0 To UBound(lines)
            SearchString = lines(i)
            Index = InStr(1, SearchString, SearchChar, CompareMethod.Binary)
            If Index <> 0 Then
                Exit For
            End If
        Next i
        Return i
    End Function
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ans = GiveBackStageText(“1.lvf”)
        MsgBox(ans)
    End Sub

经过指点之后用了readalllines
图片说明
但是为什么会多读出空行??

  • 写回答

2条回答 默认 最新

  • threenewbee 2019-01-25 23:51
    关注

    Dim lines() As String = File.ReadAllLines(文件名).ToArray()
    这样文件按照行读取到数组lines里面

    然后可以用Instr或者 Regexp.Match去匹配关键字

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思