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.
Related
When I try this code:
string value = "220510"; // The `value` variable is always in this format
string key = "30";
string title;
switch (key)
{
case "30":
title = "Date: ";
Console.WriteLine($"{title} is {value}");
break;
}
the output looks like this:
My problem is that I don't know how to insert the '-' character to separate the month, day and year because I want it to display:
Date: is 22-05-10
Please show me how to parse it.
If you have a DateTime object:
oDate.toString("yy-MM-dd");
If you have a string you can either:
sDate = sDate.Insert(2,"-");
sDate = sDate.Insert(5,"-");
or go through DateTime again (for whatever reason):
string sDate = "220510";
CultureInfo provider = CultureInfo.InvariantCulture;
DateTime sDate = Convert.ParseExact(iDate, "yyMMdd", provider);
sDate.toString("yy-MM-dd");
Your question is: How do I parse the string 220510 date format so the value comes out as 22-05-10?
In this specific case, consider using the string.Substring method to pick out the digit pairs then use string interpolation to put them back together.
const string raw = "220510";
// To do a simple parse (not using a DateTime object)
var yearString = raw.Substring(0, 2);
var monthString = raw.Substring(2, 2);
var dayString = raw.Substring(4, 2);
var string_22_05_10 = $"{yearString}-{monthString}-{dayString}";
Console.WriteLine(string_22_05_10);
I have a string variable with the value of 07/31/2016 and I need to convert this to show as July 2016. How can I do this in C#?
var input = "07/31/2016";
var date = DateTime.Parse(input);
var output = date.ToString("MMMM-yyyy");
See DateTime.Parse.
See also date and time format strings.
CultureInfo provider = CultureInfo.InvariantCulture;
var input = "07/31/2016";
var date = DateTime.ParseExact(input,"MM/dd/yyyy",provider);
var output = date.ToString("MMMM-yyyy");
This should be work:
string iDate = "07/31/2016";
DateTime oDate = Convert.ToDateTime(iDate);
Console.WriteLine(CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(oDate.Month) + " " + oDate.Year);
Parse to DateTime and call ToString() with the new format.
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();
I'm trying to get the function DoDialogwizardWithArguments that is inside a string using Regex:
string:
var a = 1 + 2;DoDialogWizardWithArguments('CopyGroup', '&act=enviarcliente', 96487, (Q.getBody().$.innerWidth()/4)*3, Q.getBody().$.innerHeight(), new Function("if(localStorage.getItem('atualizaPgsParaCli')){{Q.window.close();Q.window.proxy.reload();}}localStorage.removeItem('atualizaPgsParaCli');return true;"), false);p = q.getBOdy();
actual Regex (pattern):
DoDialogWizardWithArguments\((.*\$?)\)
Result expected:
DoDialogWizardWithArguments('CopyGroup', '&act=enviarcliente', 96487, (Q.getBody().$.innerWidth()/4)*3, Q.getBody().$.innerHeight(), new Function("if(localStorage.getItem('atualizaPgsParaCli')){{Q.window.close();Q.window.proxy.reload();}}localStorage.removeItem('atualizaPgsParaCli');return true;"), false)
The problem:
If there's another parentheses ")" that is not the parentheses of DoDialogWizardWithArguments function the Regex is getting this too.
How can i get only the function with his open and close parentheses.
If Regex is not possible, whats the better option?
Example regex link:https://regex101.com/r/kP2bQ4/1
Try this one as regex: https://regex101.com/r/kP2bQ4/2
DoDialogWizardWithArguments\(((?:[^()]|\((?1)\))*+)\)
I'd probably try to simplify it like this:
var str = #"var a = 1 + 2;DoDialogWizardWithArguments('CopyGroup', '&act=enviarcliente', 96487, (Q.getBody().$.innerWidth()/4)*3, Q.getBody().$.innerHeight(), new Function("if(localStorage.getItem('atualizaPgsParaCli')){{Q.window.close();Q.window.proxy.reload();}}localStorage.removeItem('atualizaPgsParaCli');return true;"), false);p = q.getBOdy();"
var lines = str.Split(';');
foreach(var line in lines)
{
if(line.Contains("DoDialogWizardWithArguments")){
int startPos = line.IndexOf("(");
int endPos = line.IndexOf(")");
return line.Substring(startPos+1, endPos - startPos - 1);
}
}
return "Not found";
If you don't want to detect if DoDialogWizardWithArguments was correctly written but just the function itself, try with "DoDialogWizardWithArguments([^,],[^,],[^,],([^,]),.+);".
Example:
String src = #"xdasadsdDoDialogWizardWithArguments('CopyGroup', '&act=enviarcliente', 96487, (Q.getBody().$.innerWidth()/4)*3, Q.getBody().$.innerHeight(), new Function(" + "\""
+ "if(localStorage.getItem('atualizaPgsParaCli')){{Q.window.close();Q.window.proxy.reload();}}localStorage.removeItem('atualizaPgsParaCli');return true;"
+ "\"" + "), false);p"; //An example of what you asked for
System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(#"DoDialogWizardWithArguments([^,]*,[^,]*,[^,]*,([^,]*),.+);"); //This is your function
MessageBox.Show(r.Match(src).Value);
if (r.IsMatch(src))
MessageBox.Show("Yeah, it's DoDialog");
else MessageBox.Show("Nope, Nope, Nope");
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