0

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.

5
  • 1
    Have you tried String.Join or String.Concat between them? Commented Oct 6, 2017 at 1:47
  • I think the problem here is to trick C# to take the "+" signs along with the extra quotation marks and spaces. I broke it down just to see if it would work, but it's not the ultimate goal. Commented Oct 6, 2017 at 1:50
  • Would that deal with the + signs and extra ""? Commented Oct 6, 2017 at 1:56
  • 1
    See this fiddle: dotnetfiddle.net/SVi3eG. I added some quotes to see if the result equals with desired URL string. Commented Oct 6, 2017 at 1:58
  • I used it and it worked. It looks like I was just missing the two extra quotes at the second link like domenicr said. Commented Oct 6, 2017 at 2:14

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

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="; 

Comments

0

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(); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.