我如何传递空格作为参数 [英] How do i pass a whitespace as parameter

查看:104
本文介绍了我如何传递空格作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下模型



i have the folowing model

public class Store
{
   public string StoreName {get; set;}
   public string Price {get;set;}
   public string PriceSeparator {get; set;}
   public string Currency {get;set;}
}







var storeModel = new Store();





storeModel从带有文本框的wpf窗口填充;



我有以下电话





storeModel gets populated from a wpf window with textboxes;

and i have the following call

WcfService serviceClient = new WcfServiceClient();
serviceClient.SaveStoreModel(storeModel);





在通话时我有



at the moment of the call i have the

storeModel.PriceSeparator = " ";





调试Wcf服务时我有



when debugging the Wcf Service i have

storeModel.PriceSeparator = "";





如何将模型设置为不调整调用之间的空格,或者我应该怎样做才能实现这个。



非常感谢!



我的尝试:



这就是我尝试过的事情



How set the model to not trim whitespaces between calls, or what should i do to achieve this.

Thanks very much!

What I have tried:

This is what i've tried

public class Store
{
   public string StoreName {get; set;}
   public string Price {get;set;}
   [Required(AllowEmptyStrings = true)
   public string PriceSeparator {get; set;}
   public string Currency {get;set;}
}

推荐答案

这个问题是在.NET 4.5中引入的,但仍然没有明确的解决方法;但是你可以尝试通过添加特殊的空格字符来解决这个问题。



例如,试试;

This issue was introduce back with .NET 4.5, and there still hasn't been a clear fix; However you can try to workaround this by putting special whitespace characters.

For example, try;
storeModel.PriceSeperator = "\u2007";





或者,通过放置某种关键字标识符来检测它是否为空格并在输出前应用空格。



Or alternatively, as suggested by placing some kind of keyword identifier to detect if it's a space and apply the space before output.


您可以使用我想,\ t给你一个制表符。这可能会使间距更清晰。

You could use "\t", I think, to give you a tab character. That might make the spacing more clear.
storeModel.PriceSeparator = @"\t";


对不起,我不知道对你有什么意义



我认为WCF不会过滤空间



如果真的如你所说

例如:

storeModel.PriceSeparator = storeModel.PriceSeparator .Replace(,);
Sorry,I don't know what's the significance for you

I don't think the WCF will filter Spaces

If really as you say
eg:
storeModel.PriceSeparator =storeModel.PriceSeparator .Replace(""," ");


这篇关于我如何传递空格作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆