I have text file with number of transection and amount i want to get only last line Credit amount
E.g
|D| 1000.11|
|D| 2000.88|
|D| 3000.11|
|C| 6000.11|
I want only 6000.11
I have text file with number of transection and amount i want to get only last line Credit amount
E.g
|D| 1000.11|
|D| 2000.88|
|D| 3000.11|
|C| 6000.11|
I want only 6000.11
Use Read CSV to put it into a datatable. Designate | as the delimiter. To get the second column of the last row:
yourDT.Rows(yourDT.Rows.Count-1)(1).ToString.Trim
If you want it as a numeric value (Double) then put a CDbl around it:
CDbl(yourDT.Rows(yourDT.Rows.Count-1)(1).ToString.Trim)
The reason for the -1 is that Rows is 0 index, so the first row is 0. That means if you have 4 rows, the last row is index 3. Same for the (1) index…the second column is index 1.
if it looks like above then you can try this split
str.Split("|",StringSplitOptions.RemoveEmptyEntries).Last
cheers
Use the Regex expressions to extract amount from the given text file. Find the below regex expression.
System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,“((?<=|\s)\d+.\d+(?=|))”)
Hope it helps!!
Input in text file or it is in datatable.
textFileContent
.textFileContent
. Configure it as follows:textFileContent
\|C\| (\d+\.\d+)\|
matches
, of type System.Text.RegularExpressions.MatchCollection
.creditAmountString
. Set the value as follows:matches(matches.Count - 1).Groups(1).Value
creditAmountString
to a double variable. Let’s call the double variable creditAmount
.creditAmount
variable will contain the credit amount from the last line of the text fileThis topic was automatically closed 3 days after the last reply. New replies are no longer allowed.