0

I have the string "https://www.AbcXyz.org/schema/Attributes#" I want to convert it to Uri. The line of code is

public static Uri Create(String uri){
        Uri u = new Uri(uri);
        node.Value = u;

        return new Uri(uri);
    }

But this code is returning "https://www.abcxyz.org/schema/Attributes#"

How can I get the exact string I passed? Can we have Uppercase letters in URI? because I need to use that URI in a graph database to store as triple data as a database is a case-sensitive

samir jamadar
  • 111
  • 1
  • 1
  • 7
  • Since the difference is only by the case of host name, it may considered equal according to this post: https://stackoverflow.com/questions/47746053/c-sharp-how-to-use-uri-equal. Only the paths and query strings are treated case sensitive. – Tetsuya Yamamoto Jan 24 '19 at 07:18
  • Yes, You are right. But what if I want my hostname should be same as the one which I provided. Can we do that thing here? If Yes, How? – samir jamadar Jan 24 '19 at 07:42
  • Looking at https://referencesource.microsoft.com/#System/net/System/URI.cs it doesn't seem there is a way to get your original string back. You'll have to do something else like use an `out` for your original string or use a tuple return type to return the new `Uri` and the original string. – Stuart Grassie Jan 24 '19 at 08:06

2 Answers2

2

The Uri.OriginalString property will return the original string passed to the constructor.

yaakov
  • 5,552
  • 35
  • 48
0
Dr. K
  • 1,001
  • 7
  • 7