2013-05-01 22 views
2

我有一个使用.Net框架4.0的ASP.Net项目。如果我的项目发布到我的Windows 7工作站以下行正常工作:如果在Windows 7工作站上运行ASP.Net的String.Replace的行为与在Windows 2008 R2服务器上的行为不同

strTemplate = strTemplate.Replace("<span style=\"background-color: yellow;\">", ""); 

但是,如果我发布该项目到Windows 2008 R2服务器,上面的更换不会发生。没有错误;服务器只是没有找到模式,并没有取代它。谁能告诉我为什么,或者如何解决这个问题?我试着在我的模式字符串前加上一个“@”,但是这个字符串想要在“background-color”之前的双引号结束,无论反斜杠是否存在。使用@符号时

strTemplate = strTemplate.Replace(@"<span style=""background-color: yellow;"">", ""); 

你必须把两个双引号:

+1

最有可能的,因为'strTemplate'不包含字符串您正在搜索因为 - 所以请发布导致问题的变量的示例值。 – 2013-05-01 17:08:23

+2

怀疑这是问题(只有一个评论),但我认为它会使用当前文化的字符串比较,他们可能会有所不同。 – Paparazzi 2013-05-01 17:24:03

+0

@Alexei - 没有strTemplate包含我正在搜索的字符串。如果项目是从Windows 7计算机运行的,则匹配;如果项目是从Windows 2008 R2服务器运行的,则不匹配 – Melanie 2013-05-01 18:56:46

回答

2

试试这个。

编辑: 假设您可以访问您的Windows 2008 R2服务器上运行的应用程序,尝试运行该代码,而你的Windows 7工作站上:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading; 
using System.Globalization; 

namespace CurrentCulture 
{ 
    public class Info : MarshalByRefObject 
    { 
     public void ShowCurrentCulture() 
     { 
      Console.WriteLine("Culture of {0} in application domain {1}: {2}", 
           Thread.CurrentThread.Name, 
           AppDomain.CurrentDomain.FriendlyName, 
           CultureInfo.CurrentCulture.Name); 
     } 
    } 

    class Program 
    { 
     static void Main(string[] args) 
     { 
      Info inf = new Info(); 
      // Set the current culture to Dutch (Netherlands). 
      Thread.CurrentThread.Name = "MainThread"; 
      Thread.CurrentThread.CurrentCulture = CultureInfo.CurrentCulture; 
      inf.ShowCurrentCulture(); 
      Console.Read(); 
     } 
    } 
} 

如果您的Windows 7工作站上当前文化与Windows 2008 R2服务器不同,您需要调整Windows 2008 R2线程的当前文化以符合您的期望。

您可以将线程的文化设置为一个新的文化是这样的:

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("nl-NL"); 

我的代码是从MSDN页面修改:http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.currentculture(v=vs.110).aspx

+0

谢谢,卡梅隆,但这并没有给我任何不同的结果。搜索字符串仍然不匹配。 – Melanie 2013-05-01 19:02:20

+0

我已经更新了我的答案,以包含Blam建议的'CurrentCulture'信息。 – 2013-05-01 19:55:41

+0

卡梅隆,非常感谢! – Melanie 2013-05-01 20:50:55

相关问题