【问题标题】:insert a string in an Url [duplicate]在 URL 中插入一个字符串 [重复]
【发布时间】:2018-05-04 19:07:19
【问题描述】:
string id = oUser.id.ToString();
 Image1.ImageUrl="http://graph.facebook.com/893914824028397/picture?type=large&redirect=true&width=500&height=500";

我想用字符串 id 替换 893914824028397

【问题讨论】:

  • 所以...我不想这么说,但是...您尝试了什么?有很多方法可以做到这一点 - 连接、替换、string.format、C# 字符串插值等
  • 欢迎来到 Stack Overflow。请阅读How to Ask 并分享您的研究。在网上搜索“C# 替换字符串中的变量”会产生数十万个结果,完全没有必要再问这个问题。如果您确实找到了一些东西但它没有用,那么edit您的问题包括它,并解释它做什么或不做什么。

标签: c# asp.net string url


【解决方案1】:

您可以使用 C#6 中的 String Interpolation feature,因此您的代码将如下所示:

string id = oUser.id.ToString();
Image1.ImageUrl=$"http://graph.facebook.com/{id}/picture?type=large&redirect=true&width=500&height=500";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-09
    • 2020-12-19
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 2015-02-11
    相关资源
    最近更新 更多