我从excel文件创建XML文件。我从变量sObserved中的一个单元格中保存一个字符串。在该字符串中,我有一个字符"&"
,它应该被替换为"&"
,当我有一个字符";"
时,它应该被替换为";"
。
我用这个函数替换,这是我的代码:
sObserved = Replace(sObserved, "&", "&")
sObserved = Replace(sObserved, ";", ";")
但这不能很好,因为当它取代"&"
上的"&"
时,";"
会出现,下一步操作会将其更改为"&;"
如果我改变订单也会出错,因为然后签署“&” ";"
中的内容将被替换。
有没有可能像我想要的那样更换它?我会感激任何想法因为我被困在这里。
答案 0 :(得分:2)
试试这个:
private void DoLogin(object obj)
{
ShowAnotherView = false;
if (UserName == "1" && UserPassword == "1")
{
container.RegisterType<Object, TheUpperControl>("ModuleItems");
Uri viewNav = new Uri("ModuleItems", UriKind.Relative);
regionManager.RequestNavigate(RegionNames.TheUpperRegion, viewNav);
regionManager.RequestNavigate(RegionNames.TheBottomRegion, viewNav);
LoadTheOtherModule(); //load the other module
var loginView = regionManager.Regions[RegionNames.TheWholeRegion].Views.ElementAt(0);
regionManager.Regions[RegionNames.TheWholeRegion].Remove(loginView); //remove the login view
//MessageBox.Show("");
}
else
ShowPromptingMessage = true;
}
private void LoadTheOtherModule()
{
Type moduleType = typeof(ModuleItems.ModuleItemsModule);
ModuleInfo mi = new ModuleInfo()
{
ModuleName = moduleType.Name,
ModuleType = moduleType.AssemblyQualifiedName,
};
IModuleCatalog catalog = container.Resolve<IModuleCatalog>();
catalog.AddModule(mi);
catalog.Initialize();
IModuleManager moduleManager = container.Resolve<IModuleManager>();
moduleManager.LoadModule(moduleType.Name); //run Initialize() of the other module
}
答案 1 :(得分:1)
此功能来自http://www.codeproject.com/Articles/33064/VBScript-HTML-Encode。您可能需要调整它,但它会通过字符检查进行字符处理。
Function HTMLEncode(ByVal sVal)
sReturn = ""
If ((TypeName(sVal)="String") And (Not IsNull(sVal)) And (sVal<>"")) Then
For i = 1 To Len(sVal)
ch = Mid(sVal, i, 1)
Set oRE = New RegExp : oRE.Pattern = "[ a-zA-Z0-9]"
If (Not oRE.Test(ch)) Then
ch = "&#" & Asc(ch) & ";"
End If
sReturn = sReturn & ch
Set oRE = Nothing
Next
End If
HTMLEncode = sReturn
End Function
答案 2 :(得分:1)
您所需要的是将输出编码为HTML友好的函数:htmlEncode。人们已经在网上写了几个脚本/函数,这里有一个:
' Encode an string so that it can be displayed correctly
' inside the browser.
'
' Same effect as the Server.HTMLEncode method in ASP
Function HTMLEncode(ByVal Text As String) As String
Dim i As Integer
Dim acode As Integer
Dim repl As String
HTMLEncode = Text
For i = Len(HTMLEncode) To 1 Step -1
acode = Asc(Mid$(HTMLEncode, i, 1))
Select Case acode
Case 32
repl = " "
Case 34
repl = """
Case 38
repl = "&"
Case 60
repl = "<"
Case 62
repl = ">"
Case 32 To 127
' don't touch alphanumeric chars
Case Else
repl = "&#" & CStr(acode) & ";"
End Select
If Len(repl) Then
HTMLEncode = Left$(HTMLEncode, i - 1) & repl & Mid$(HTMLEncode, _
i + 1)
repl = ""
End If
Next
End Function
参考:http://www.devx.com/vb2themax/Tip/19162
此处还有另一个:http://www.codeproject.com/Articles/33064/VBScript-HTML-Encode 但这似乎编码了所有不是字符或字母的东西。这个中的正则表达式可能会扩展得更好,以包含那些可以用于HTML的那些。
Function HTMLEncode(ByVal sVal)
sReturn = ""
If ((TypeName(sVal)="String") And (Not IsNull(sVal)) And (sVal<>"")) Then
For i = 1 To Len(sVal)
ch = Mid(sVal, i, 1)
Set oRE = New RegExp : oRE.Pattern = "[ a-zA-Z0-9]"
If (Not oRE.Test(ch)) Then
ch = "&#" & Asc(ch) & ";"
End If
sReturn = sReturn & ch
Set oRE = Nothing
Next
End If
HTMLEncode = sReturn
End Function