I have a text file contained a series at digits and characters.that are separated by comma.how digits come be read and replaced reverse?
file example:book,215420,id,name,4520
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pradeep ShetRank #595 · 4K reputationPosted Jul 21, 2014, 9:00 PM EDT
First Split the text with ,
string[] strsplit = text.Split(new char[]{','});
You will get an array of string
Now you can check each string whether its a number or characters
Once done, use Reverse() method to reverse the digits.
Hope you got the answer. Mark it answered if it helped you.
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 21, 2014, 10:24 PM EDT
Hi,
Try following code it might help you.
string test = "book,215420,id,name,4520";
var splitData = test.Split(new char[] { ',' });
string pattern = @"^\d*$";
List
foreach (string s in splitData)
{
if (Regex.IsMatch(s, pattern))
{
string re = string.Join("", s.Reverse());
reverseData.Add(re);
}
else
{
reverseData.Add(s);
}
}
Console.WriteLine("Original String:" + test);
Console.WriteLine("New String:" + string.Join(",", reverseData));
mohammad9 reputationPosted Jul 26, 2014, 2:53 AM EDT
thanks for your answer
my file digit such as 41/20/39,14.210.333,17/26/29,24.0000 in addition to the above,there
so what do you do?
VulpesRank #55 · 29.2K reputationPosted Jul 26, 2014, 3:40 AM EDT
14/02/93,41.012.333,71/62/92,42.0000
or that it should be:
93/02/14,333.012.41,92/62/71,0000.42
or that it should be:
0000.42,92/62/71,333.012.41,93/02/14 ?
mohammad9 reputationPosted Jul 26, 2014, 4:06 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 26, 2014, 5:20 AM EDT
Similarly reversing the fourth item : 24.0000 should give : 00.0042 rather than 0000.42
So try this:
The output is: