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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jul 26, 2014, 9:20 AM
Similarly reversing the fourth item : 24.0000 should give : 00.0042 rather than 0000.42
So try this:
The output is:
mohammadPosted Jul 26, 2014, 8:06 AM
VulpesPosted Jul 26, 2014, 7:40 AM
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 ?
mohammadPosted Jul 26, 2014, 6:53 AM
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?
Jignesh TrivediPosted Jul 22, 2014, 2:24 AM
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));
Pradeep ShetPosted Jul 22, 2014, 1:00 AM
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.