Url string editing

Hi @vvaidya and @ClaytonM

I want to edit this link https://cotthosting.com/NYOnondagaExternal/HTML5Viewer/wscottfilexfer.asmx/LoadThumbnail?requestID=4d48fb31-1d1d-4c10-9997-193a9189f762&idx=0&width=97&height=97

i want idx=0 to increment i will use i=i+1.
width=97 to 3000 and height=97 to 3000 will be static.

Hi.

Look into using Regex.Replace()
This will let you set a pattern for β€œidx=(.*)&”, then you can replace it with the new number. If you get stuck, let us know where you have a problem understanding.

Regards.

1 Like

idx is getting deleted i just want to edit after the equal to also height and width to =3000

do you know what is deleting it? Is it code you are using?

System.Text.RegularExpressions.Regex.Replace(ul, "idx=(.*)&”,β€œ1”)

Add in the part from your pattern next to β€œ1”, like this:
System.Text.RegularExpressions.Regex.Replace(ul, "idx=(.*)&”,"idx="+"1”+"&")

Then, you can replace β€œ1” with a variable that you increment.

You can do the same thing for the weight and height.

1 Like

tnx for the help. when i run this code &width=97 gets deleted

It might be the β€œ(.*)” part of the pattern.
Try changing it to digits, like this:
System.Text.RegularExpressions.Regex.Replace(ul, "idx=[0-9]{1,4}&”,"idx="+"1”+"&")

1 Like

cool it works .Let me try completing the rest.

I’m using i=i+1 for increment the value. where should I place the i in this System.Text.RegularExpressions.Regex.Replace(ul, "idx=[0-9]{1,4}&”,"idx="+"1”+"&")

replace β€œ1” with i.ToString
System.Text.RegularExpressions.Regex.Replace(ul, "idx=[0-9]{1,4}&”,"idx="+i.ToString+"&")

1 Like

can u let how to change the width and height to 3000 also I ran this code
β€˜System.Text.RegularExpressions.Regex.Replace(ul, β€œidx=[0-9]{1,4}&”,β€œwidth”+β€œ3000”+”&”)’
extra width is getting added

For width, you need to replace β€œidx=” to β€œwidth=” in each place
System.Text.RegularExpressions.Regex.Replace(ul, β€œwidth=[0-9]{1,4}&”,β€œwidth=”+β€œ3000”+”&”)

For heigth, will be like this:
System.Text.RegularExpressions.Regex.Replace(ul, β€œheight=[0-9]{1,4}”,β€œheight=”+β€œ3000”)
I left off the β€œ&” next to height since it’s on the end.

If you run into problems you might instead place the & infront of the keyword, like this:
System.Text.RegularExpressions.Regex.Replace(ul, β€œ&idx=[0-9]{1,4}”,β€œ&idx=”+i.ToString)

System.Text.RegularExpressions.Regex.Replace(ul, β€œ&width=[0-9]{1,4}”,β€œ&width=”+"3000")

System.Text.RegularExpressions.Regex.Replace(ul, β€œ&height=[0-9]{1,4}”,β€œ&height=”+"3000")

1 Like



the result is getting messed up.

I’m not a regex guy (and your code from last post seems to do the job just fine), but it seems that the start of the URL is static and the rest is either changed or iterated upon.
Wouldnt it be easier at this point to drop regex and use string formatting?
Something like:
string completeUrl = String.Format("https://cotthosting.com/NYOnondagaExternal/HTML5Viewer/wscottfilexfer.asmx/LoadThumbnail?requestID=4d48fb31-1d1d-4c10-9997-193a9189f762&idx={0}&width={1}&height={2}", idx, width, height)

idx width and height can be int variables.

If beginning also changes, that could be good for regex (get all before &idx).
What do you think?

Yeah good point @andrzej.kniola, but I was assuming his url already had the values in the url, so using Regex was a way to find those values in the url without knowing them.

lol, by the way, you might use the Snipping tool, which is software you can use to take screenshots.

Your idx value is 0, you need to add 1 to it. So instead of i.ToString change it to (i+1).ToString, or change how you are incrementing it so it starts on 1 instead of zero.

Hope that helps.

If requestID would also be part of the format call, it pretty much becomes filling the blanks game. Or combine both approaches to get values out and reconstruct the URL.
In any case, a pure regex approach will be more flexible, but in the long run someone has to support it and debugging that can be pretty hard if one is not versed in regex (I know I’m not so I try to avoid complex regexes).

Oh I understand, so basically store the entire url to a string in your code, then you just play the replace game.

1 Like

yeah exactly.