How to replace last characters in string?

studio

#1

I have a url like ‘abcd&page=0’. The last number changes dynamically. I have to replace the last number with a ‘counter’ value. How do I do this?


#2

@shrutika

you can use variable to store the dynamic value and concatenate to url like…

‘abcd&page=’+Variblename


#3

the above url is stored in a variable say “url”. Also page= could be one or two digit.


#4

Hey @shrutika,
Try this…
url = ‘abcd&page="+counter.tostring+"’

Let me know if any issue…

Best Regards,
SP


#5

Hi @shrutika

You could use split method for your url string, like this:

It would give you the output you want:
image

See attached xaml file for reference:
LastCharacter.xaml (6.1 KB)


#6

Say your variable is like
url = "abcd&page=[counter]"

You can use
url.Replace("[counter]", counterNo.ToString)

where counterNo can be your integer variable for the last digits.


#7

Thank you. I have other query. I have a string like MyString= “

<href=‘abc.com’>ABC Corp
”. I need only the middle content and remove everything in between <>. I have used MyString.Replace("<*>",""). But this doesnt seem to work. Please help

#8

Forum removes the html tags, but you can post them using the code snipped tag:
image

If you want to get ABC Corp from, for example:
<a href=‘abc.com’>ABC Corp</a>
you could use this Regex expression:
(?<=>).+(?=<)

You can use it like this:
System.Text.RegularExpressions.Regex.Match(inputString,"(?<=>).+(?=<)").ToString

This should return a string with just ABC Corp :slight_smile:


#9

I was able to it with this:
system.Text.RegularExpressions.Regex.Replace(inputString.Replace("<","").Replace(">",""),"<.*?>",String.Empty)


#10

I have a url like: myURL=“https://abc.com/overview/overview’”. I need to remove only the last ‘overview/’ so that the output will be myURL="https://abc.com/overview’. I have used myURL.Replace but it replaces both the instances. How do I achieve this?


#11

@shrutika ,
Use lastindex() method and pass ‘overview’ as parameter. With this , you’ll get an index position and now do a substring using that index

Regards,
SP


#12