How to get ths parts out of url via RegEx [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have two urls:
http://sp2013/sites/1234
and
http://sp2013/pwa/projectsites/projectdetails.aspx?projuid=1234-123-123-123456-123456
I want to get from the first url the last part (always a number)
1234
and from the second url also the last part (guid)
1234-123-123-123456-123456
How could i achieve this through RegEx or maybe with string operations in C#?

string s = "http://sp2013/sites/1234";
var firstURLlastPart = new Uri(s).Segments.Last();
string s = "http://sp2013/pwa/projectsites/projectdetails.aspx?projuid=1234-123-123-123456-123456";
var secondURLlastPart = s.Split('=').Last();

Just split at '/' and take the last chunk for the first case.
str.Split('/').Last()
Split at '=' and take last chunk for second case
str.Split('=').Last()

(?!\/|\=).[-0-9]+$
It's working for both. But it also accepts if in first example will be number in format like this:
12345-4568

Related

C# Regex meet first match and take everything from start of string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a string input which looks like:
var price = "£1.33(including postage)";
I'd like to take out the first part of the string before ( so that the output of regex would look like this:
"£1.33"
I'm new with Regex so I'm not quite sure how to do this, can someone help me out?
P.S. I thought of doing a substring, but that wouldn't work since price can have more decimals, and can be a larger price, so this option definitely wouldn't work
do you have to use regex?
much easier if you use split
string result = price.Split('(').First();
You don't need Regex for this if you have the same basic format of the "price" just different values.
var result = price.Substring(0, price.IndexOf("("));.

Get the Special Character from URL [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Url is like That:
http://localhost:620251/Default.aspx/?group=Bkgbdsconsumer & Retailmailinglist
Want the group value on cs page:
Bkgbdsconsumer & Retailmailinglist
I ma doing this:
string group= HttpUtility.UrlEncode(Request.QueryString["group"]);
EDIT:
Ok, as I thought, there is no space before and after & in your URL.
Also port number is too big 620251 (max is 65535 as I think).
// 'fixed' port number
string url = #"http://localhost:12345/Default.aspx/?group=Bkgbdsconsumer&Retailmailinglist";
Uri myUri = new Uri (url);
var groupValue = HttpUtility.ParseQueryString (myUri.Query)["group"];
string[] allKeysWithoutValue = HttpUtility.ParseQueryString (myUri.Query).GetValues (null);
Now allKeysWithoutValue is an array with one element Retailmailinglist.

RegExp to search words starts with numbers and special characters only using C# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to perform a search to C# list object to find all products starts with any number or special characters only. I am looking for a Regular expressions for this scenario.
Please help
Assuming you list is a list of string:
var newList = yourList.Where(element => Regex.IsMatch(element, #"^[^a-z]", RegexOption.IgnoreCase);
It will give you a sublist of all the elements that doesn't start with a letter in the range a-z.

Grabbing part of a String [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a string that I am grabbing that is input as:
05/22/2015
Eligibility
05/06/2015
Date of Death
I need 05/06/2015. The dates will change as the program runs through a database, and I am just a little unsure on how to always be grabbing the correct one.
So you need the second date only? Is it always going to be the 3rd line? If so you can do
var secondDate = myData.Split(new [] { Environment.NewLine }, StringSplitOptions.None)[2];
If the new line isn't for certain; /n vs /r/n, use:
var secondDate = myDate.Split(Environment.Newline.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[2];
If I understand you correctly, your string has 4 lines and you want the part of the string between linebreak 2 and 3.
Search for the positions of the second and third linebreak \n and use the substring derived of these positions.

Find the number of characters that are present in every line into a List<string> [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need to find the number of characters that are present in every line, within a List:
So, if for example, the string is
Ajdahnfj
Jnbafdbn
Jadnjadg
a,j,d,n are common for each line. Therefore the answer is 4.
No case sensitive is required
Regards
Here's a high level description of what I would do:
Make a collection of characters
initialize it to represent all of the characters in the first line
for each other line,
for each character in the collection, check if it's in that line. if it isn't then remove it from the list
return the resulting collection of characters

Categories

Resources