现在我正在制作一个程序,让你更容易修改游戏。在常规游戏中,您必须打开文件并浏览动画。我想让它变得更容易。我已经完成了程序的其他部分,但是到了我需要帮助的最后一部分。我希望能够获取所有形式的第一个动画名称,然后是内部动画名称,并将其与之一起使用。所以我可以制作一个易于使用的编辑器。我知道这很可能涉及正则表达式而且我相当糟糕,我还在尝试重新学习VB.net,而不是长时间使用该语言。如果有人可以帮助我,我会非常感激:
我要加载的文件:
animation "idle0"
{
animation "idle_yoga";
};
animation "idle1"
{
animation "idle_pants";
};
答案 0 :(得分:1)
这里有一个示例代码,可以执行您的操作:
Dim dict As Dictionary(Of String, String) = New Dictionary(Of String, String)()
Try
Dim sr As System.IO.StreamReader = New System.IO.StreamReader("path to the file")
Dim line As String
Dim started As Boolean = False
Dim inside As Boolean = False
Dim firstInput As String = ""
Do
line = sr.ReadLine()
If (line IsNot Nothing) Then
If (line.ToLower().Contains("animation")) Then
If (started AndAlso inside) Then
'Animation
Dim curItem As String = line.ToLower().Split(New String() {"animation"}, StringSplitOptions.None)(1).Trim()
If (curItem.Substring(curItem.Length - 1, 1) = ";") Then curItem = curItem.Substring(0, curItem.Length - 1)
curItem = curItem.Replace("""", "")
dict.Add(firstInput, curItem)
started = False
inside = False
ElseIf (Not inside) Then
'Group name
Dim curItem As String = line.ToLower().Split(New String() {"animation"}, StringSplitOptions.None)(1).Trim()
curItem = curItem.Replace("""", "")
firstInput = curItem
started = True
End If
ElseIf (started AndAlso line.Contains("{")) Then
inside = True
End If
End If
Loop Until line Is Nothing
sr.Close()
Catch
End Try
此代码从文件中读取信息(您逐行发布的代码)并执行所需的分组。最后,我选择了Dictionary
(ListBox
可能不是最好的控件;你可能会考虑更好地使用ListView
因为重点是向你展示这种情况怎么样?解决。我想代码的作用非常清楚:你必须扩展/调整它以适应你的实际需求,尽管主要结构应该是这些行上的东西。