Pucho
Pucho

Reputation: 380

How can I make a string out of a complex URL address

I've been trying to make this URL a workable string in C#, but unfortunately using extra "" or "@" is not cutting it. Even breaking it into smaller strings is proving difficult. I want to be able to convert the entire address into a single string.

this is the full address:

<https://my.address.com/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID=ATTPCi6c.mZInSt5o3t_Xr8&sIDType=CUID&&sInstance=Last&lsMZV_MAT="+URLEncode(""+[Material].[Material - Key])+"&lsIZV_MAT=>

I've also tried this:

string url = @"https://my.address.com/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID=ATTPCi6c.mZInSt5o3t_Xr8&sIDType=CUID&&sInstance=Last&lsMZV_MAT=";
string url2 = @"+ URLEncode("" +[Material].[Material - Key]) + """"";
string url3 = @"&lsIZV_MAT=";

Any help is appreciated.

Upvotes: 0

Views: 98

Answers (4)

Him
Him

Reputation: 19

I just made two updates t&lsMZV_MAT=" to t&lsMZV_MAT="" AND [Material - Key])+" to [Material - Key])+""

string s = @"<https://my.address.com/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID=ATTPCi6c.mZInSt5o3t_Xr8&sIDType=CUID&&sInstance=Last&lsMZV_MAT=""+ URLEncode([Material].[Material - Key])+""&lsIZV_MAT=>";
        Console.Write(s);
        Console.ReadKey();

Upvotes: 0

Tetsuya Yamamoto
Tetsuya Yamamoto

Reputation: 24957

The simplest solution is put additional quotes inside string literal and use string.Concat to join all of them into single URL string:

string url = @"https://my.address.com/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID=ATTPCi6c.mZInSt5o3t_Xr8&sIDType=CUID&&sInstance=Last&lsMZV_MAT=";
string url2 = @"""+URLEncode(""+[Material].[Material - Key])+""";
string url3 = @"&lsIZV_MAT=";

string resultUrl = string.Concat(url, url2, url3);

NB: You can use Equals method or == operator to check if the generated string matches with desired URL string.

Upvotes: 1

domenicr
domenicr

Reputation: 352

You are missing the triple quotes at the beginning of url2

string url = @"https://my.address.com/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID=ATTPCi6c.mZInSt5o3t_Xr8&sIDType=CUID&&sInstance=Last&lsMZV_MAT=";
string url2 = @"""+URLEncode(""+[Material].[Material - Key])+""";
string url3 = @"&lsIZV_MAT=";

Upvotes: 1

Shadow
Shadow

Reputation: 143

This may be a bit of a workaround rather than an actual solution but if you load the string from a text file and run to a breakpoint after it you should be able to find the way the characters are store or just run it from that.

You may also have the issue of some of the spaces you've added being left over which StringName.Replace could solve if that's causing issues.

I'd recommend first checking what exactly is being produced after the third statement and then let us know so we can try and see the difference between the result and original.

Upvotes: 1

Related Questions