|
Hi,
I want to separate number and date and time from a string in c#. here is an example:
+CMGR: "REC READ","+923365483536",,"10/09/15,08:16:11+20"
from this i want to put cell number in one array and date and time in another.I dont know how to do this.
Thanks for any kind of help in advance
Regards,
Aeman
|
|
|
|
|
Well, you could always use a string split on this based on the commas and take the array items at index 1 and index 3.
|
|
|
|
|
index 3 and 4!
I cannot remember: What did I before google?
|
|
|
|
|
So cell isn't stored in the bit +9....? Index 3 is an empty string in his example.
Nevermind - I see what you're saying. I'd missed the , in the date.
I'm not a stalker, I just know things. Oh by the way, you're out of milk. Forgive your enemies - it messes with their heads
My blog | My articles | MoXAML PowerToys | Onyx
modified on Tuesday, March 29, 2011 9:40 AM
|
|
|
|
|
You could use a regular expression but then you may end up with not one problem but two
using System.Text.RegularExpressions;
...
string txt = "+CMGR: \"REC READ\",\"+923365483536\",,\"10/09/15,08:16:11+20";
Match m = Regex.Match(txt, @"[0-9]{2}/[0-9]{2}/[0-9]{2},[0-9]{2}:[0-9]{2}:[0-9]{2}");
if(m.Success)
{
String date = m.Value.Replace(",", " ");
DateTime dt = DateTime.Parse(date);
}
The snippet above should work but you may want to refine the expression. I just hacked that one up quickly
"You get that on the big jobs."
|
|
|
|
|
May I humbly suggest Rive[^]?
|
|
|
|
|
Try to use regular expression,MAN.
Hope this helps.
Hi, i am from china.Like to make friends with you from all of the world.
|
|
|
|
|
It's very easy
First store the entire string in a string variable
and then use the split method and assign it to a character array
split(",,")
and from that array fetch the appropriate value like
string s="+CMGR: "REC READ","+923365483536",,"10/09/15,08:16:11+20";
char[] temp=s.split(",,");
now your temp[1] consists both time and date.
if you want separate both use the same technique.
|
|
|
|
|
Hi,
I get a program c# when googling that validates the IBAN :
static bool isIban (string code_iban)
{
code_iban = code_iban.ToUpper () ;
StringBuilder sb = new StringBuilder ();
foreach ( char car in code_iban)
{
if (char.IsDigit (car) || char.IsLetter (car))
sb.Append (car);
}
code_iban = sb.ToString ();
if (code_iban.Length < 15 || code_iban.Length > 34)
return false;
string iban = code_iban.Substring(4, code_iban.Length - 4) + code_iban.Substring(0, 4);
StringBuilder sb2 = new StringBuilder ();
foreach (char c in iban)
{
int entier;
if (char.IsLetter(c))
entier = Convert.ToChar (c) - Convert.ToChar ("A") + 10;
else
entier = Convert.ToChar (c) - Convert.ToChar ("0");
sb2.Append (entier);
}
string checkSumString = sb2.ToString();
int checksum = int.Parse(checkSumString.Substring(0, 1));
int i = 1;
while (i < checkSumString.Length)
{
int v = int.Parse(checkSumString.Substring(i, 1));
checksum *= 10;
checksum += v;
checksum = checksum % 97;
System.Math.Max(System.Threading.Interlocked.Increment(ref i), i - 1);
}
if (checksum == 1)
return true;
else
return false;
}
}
I understand all only the functionality of System.Math.Max(System.Threading.Interlocked.Increment(ref i), i - 1);
ty
|
|
|
|
|
Well, Math.Max is retrieving the maximum of i or i-1. Interlocked.Increment is used to increment i and store it all as an atomic action.
|
|
|
|
|
Hi,
If u can give me the // algorithme of this.I can do this like this simply
Math.Max( ref i , i-1)
i ++;
why using of Interlocked.Increment???????
ty
|
|
|
|
|
You shouldn't. In this case, it's absolutely no use whatsoever - frankly, it looks like somebody is trying to be too clever for their own good. Interlocked increment only makes sense in multi-threaded scenarios where there is a possibility that somebody else may increment a shared variable. As i is local, it's pointless. This code looks like obfuscation through stupidity.
|
|
|
|
|
Pete O'Hanlon wrote: obfuscation through stupidity
5
|
|
|
|
|
This line:
System.Math.Max(System.Threading.Interlocked.Increment(ref i), i - 1);
seems utterly stupid to me. Comparing a number which is increased to what it was before and taking the maximum will always return the increased number. Even so, nothing is done with the return value. And why is this increase done using the interlocked class? Doesn't look terribly multi-threaded to me and if it is then you need additional locking.
i++ is probably what you want, and I would expect the loop initialisation to set i = 0 , rather than i = 1 on casual inspection.
Regards,
Rob Philpott.
|
|
|
|
|
it doesn't make sense at all; i is a local variable, no other thread can touch it, so the whole statement boils down to i++ and the while loop should have been a for loop.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
You have already asked about this here[^]
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Yes, however this time there was a whole new sentence, and a big code snip, so we could provide more relevant comments.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
And he is using C# not JavaScript
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
He is flexible for now, in the end he'll really want JavaScript code doing the same. Just you wait.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Using a a Binder class for connecting all Event and Handlers of classes can make those classes fully decoupled. Is it the standard way to implement a project ?
|
|
|
|
|
Is this a WinForms application? ASP.NET? WPF? Silverlight?
Whether binding is used as standard depends on which type of application it is.
|
|
|
|
|
Could we consider it a design pattern for general ?
I think it's useful for building desktop application.
|
|
|
|
|
You can use it in pretty much any type of application, but how easy it is depends on the underlying infrastructure. WPF and Silverlight are built with binding in mind, so pretty much everything can be databound and the separation is a well known pattern called MVVM. WinForms provides less support for binding. If you're looking for a decoupled event subsystem, I wrote an EventPool[^] here that might be of interest.
|
|
|
|
|
|
hi,
i've got some warnings which i couldnt resolve... Could somebody pls help me with it?
The list of warnings are:
Warning 1 Object reference not set to an instance of an object. 0 0
Warning 2 The referenced component 'DockingToolbar' could not be found.
Warning 3 The referenced component 'ImageLib.Imaging' could not be found.
Warning 4 The referenced component 'ImageLib.Math' could not be found.
Warning 5 The referenced component 'SourceGrid2' could not be found.
Warning 6 The referenced component 'SourceLibrary' could not be found.
Warning 7 The referenced component 'WeifenLuo.WinFormsUI' could not be found.
|
|
|
|