am new in c# so how to replace the string
for example:-
label1.Content = "Bal.Rs." + 100;
How to get the 100 only while we save from label1.Text???
Here you go:
string OnlyNumbered = Regex.Match(label1.Content.ToString(), #"\d+").Value;
try doing this
string input="abc 123"
string result = Regex.Replace(input, #"[^\d]", "");
//output result=123
^\d specify not number
Hope this will help
Related
I have string value like this Rs.100 - Rs.250 Now I want only 250 from this string.
I tried this but it's not getting output
var result = str.Substring(str.LastIndexOf('-') + 1);
UPDATE
string result = price.Text;
string[] final_result = result.Split('.');
dynamic get_result = final_result(1).ToString();
price.Text = final_result.ToString;
Try this code after getting the result of Rs.250.
var data = Regex.Match(result, #"\d+").Value;
Do it like this:
string str = "Rs.100-Rs.250";
var result = str.Substring(str.LastIndexOf('-') + 1);
String[] final_result = result.Split('.');
var get_result = final_result[1].ToString();
this will get 250 as you wanted.
try this
var result = ("Rs.100 - Rs.250").Split('-').LastOrDefault().Split('.').LastOrDefault();
var myPath = HttpContext.Current.Request.Url.AbsolutePath;
// output: myApplication/myFolder/myPage.aspx
var pageName = Path.GetFileName(myPath);
//output: myPage.aspx
I am trying to output "myFolder/myPage.aspx" without the application path.
Is there built-in option to return that or I would need to use regular expression to get what I need?
Thanks
You should be able to make use of HttpContext.Current.Request.Url.Segments and then a simple string concat:
String[] segments = HttpContext.Current.Request.Url.Segments;
string result = segments[1] + segments[2];
or instead of string concat, use: string result = Path.Combine(segments[1],segments[2]);
This should work
public ActionResult oihoi(string ImageName
{
string _FileName = Path.GetFileName(ImageName.FileName);
string folderpath = "UploadedFiles/WebGallery";
string path = Server.MapPath("~/" + folderpath);
string firstsegment = "";
}
I'm trying to concatenate an Arabic string with a leading DateTime, I have tried in various way but the DateTime always ends up at the end of the string
var arabicText = "Jim قام بإعادة تعيين هذه المهمة إلى John";
var dateTime = DateTime.Now;
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("ar-AE");
string test1 = arabicText + " :" + dateTime.ToString();
string test2 = arabicText + " :" + dateTime.ToString(ci);
So when this is displayed it should show
Jim قام بإعادة تعيين هذه المهمة إلى John :02/10/2012
but I always seem to end up with
02/10/2012: Jim قام بإعادة تعيين هذه المهمة إلى John
Any ideas would be apprecicated
You can use with this code
var strArabic = "Jim قام بإعادة تعيين هذه المهمة إلى John";
var strEnglish = dateTime.ToString() ;
var LRM = ((char)0x200E).ToString(); // This is a LRM
var result = strArabic + LRM + strEnglish ;
Try using string.Format:
string test1 = string.Format("{0}: {1}", arabicText, dateTime.ToString());
That should produce the result you're looking for.
Arabic text goes from right to the left, so the version you end up with is correct.
If you really want it another way, why don't you just swap the arguments order?
Have you tried the string.format() method ? Maybe it can solve your problem.
I am trying to split the string. Here is the string.
string fileName = "description/ask_question_file_10.htm"
I have to remove "description/" and ".htm" from this string. So the result I am looking for "ask_question_file_10". I have to look for "/" and ".htm" I appreciate any help.
You can use the Path.GetFileNameWithoutExtension Method:
string fileName = "description/ask_question_file_10.htm";
string result = Path.GetFileNameWithoutExtension(fileName);
// result == "ask_question_file_10"
string fileName = Path.GetFileNameWithoutExtension("description/ask_question_file_10.htm")
try
string myResult = fileName.SubString (fileName.IndexOf ("/") + 1);
if ( myResult.EndsWith (".htm" ) )
myResult = myResult.SubString (0, myResult.Length - 4);
IF it is really a path then you can use
string myResult = Path.GetFileNameWithoutExtension(fileName);
EDIT - relevant links:
http://msdn.microsoft.com/en-us/library/system.io.path.getfilenamewithoutextension.aspx
http://msdn.microsoft.com/en-us/library/hxthx5h6.aspx
http://msdn.microsoft.com/en-us/library/2333wewz.aspx
http://msdn.microsoft.com/en-us/library/system.string.length.aspx
string fileName = "description/ask_question_file_10.htm";
string name = Path.GetFileNameWithoutExtension(fileName);
On my forum I have a lot of redundant link data like:
[url:30l7ypk7]http://www.box.net/shared/0p28sf6hib[/url:30l7ypk7]
In regexp how can I change these to the format:
http://www.box.net/shared/0p28sf6hib
string orig = "[url:30l7ypk7]http://www.box.net/shared/0p28sf6hib[/url:30l7ypk7]";
string replace = "$1";
string regex = #"\[url:.*?](.*?)\[/url:.*?]";
string fixedLink = Regex.Replace(orig, regex, replace);
This isn't doing it totally in Regex but will still work...
string oldUrl = "[url:30l7ypk7]http://www.box.net/shared/0p28sf6hib[/url:30l7ypk7]";
Regex regExp = new Regex(#"http://[^\[]*");
var match = regExp.Match(oldUrl);
string newUrl = string.Format("<a href='{0}' rel='nofollow'>{0}</a>", match.Value);
This should capture the string \[([^\]]+)\]([^[]+)\[/\1\] and group it so you can pull out the URL like this:
Regex re = new Regex(#"\[([^\]]+)\]([^[]+)\[/\1\]");
var s = #"[url:30l7ypk7]http://www.box.net/shared/0p28sf6hib[/url:30l7ypk7]";
var replaced = s.Replace(s, string.Format("{0}", re.Match(s).Groups[1].Value));
Console.WriteLine(replaced)
This is just from memory but I will try to check it over when I have more time. Should help get you started.
string matchPattern = #"\[(url\:\w)\](.+?)\[/\1\]";
String replacePattern = #"<a href='$2' rel='nofollow'>$2</a>";
String blogText = ...;
blogText = Regex.Replace(matchPattern, blogText, replacePattern);