我解析一个文本文件中获取设置数据蓝牙:
这个值可以被禁用或启用,有*标记。
我遇到的问题是,它一如既往的返回状态“已启用”,如果不管其禁用。
难道这是由于该文本阅读其从具有在被缩进该行的前一个标签。我怎样才能解决这个工作?
private String GetBluetoothStatus(String FilePath)
{
String[] lines = File.ReadAllLines(FilePath);
int index = 0;
string status = "";
foreach (String s in lines)
{
if (s == "Bluetooth")
{
if (lines[index + 1].StartsWith("*"))
status = "Disabled";
else
status = "Enabled";
return status;
}
index += 1;
}
return status;
}
该文本文件低于:
BIOSConfig 1.0
;
; Originally created by BIOS Configuration Utility
; Version: 4.0.25.1
; Date="2018/08/06" Time="15:42:35" UTC="-5"
;
; Found 182 settings
;
Power On When AC Detected
*Disabled
Enabled
Power On When Lid is Opened
*Disabled
Enabled
Fast Boot
*Disable
Enable
Bluetooth
Disabled
*Enabled
Wireless Network Device (WLAN)
Disabled
*Enabled
LAN / WLAN Auto Switching
Disabled
*Enabled
更改以下行
if (lines[index + 1].StartsWith("*"))
至
if (lines[index + 1].Trim().StartsWith("*Disabled"))
更好地利用qazxsw POI像你刚才提到qazxsw POI Contains
也出现在同一行以下。
Enable
你做Disable
但如果我们看看你的配置文件将其与空间/制表开始。
尝试测试if (lines[index + 1].Contains("*Disabled"))
之前删除这个空格/制表检查值。
如果修剪不工作,尝试lines[index + 1].StartsWith("*")