-3

I want to extract the debited amount from the SMS

my sms content is

Cash withdrawal of Rs3,000.00 made on Kotak Debit Card X2694 on 08-01-2020 at #Acoount Number#.Avl bal is Rs 110.32.Not you?Visit kotak.com/fraud. Transactions on non-Kotak ATMs are chargeable beyond 5 per month(3 for Metro locations), if applicable, as per your account variant. Visit www.kotak.com for details.

Ashish
  • 6,791
  • 3
  • 26
  • 48
Nitin Zagade
  • 71
  • 1
  • 7

1 Answers1

2

As suggested by Anunay, regex would solve your issue with a single line.

Personally, I'm a newbie to regex. A naive method I could suggest is to parse the string based on the occurrence of "Rs" and ".". Then, remove all the (,)commas and convert the String to a float.

messageString = 'Your message as a String'
startIndex = messageString.index('Rs') + 2
endIndex = messageString.index('.') + 3
debitAmount = float(messageString[startIndex: endIndex].replace(',',''))
print(debitAmount)

Sorry, for my Python implementation.

Jagan
  • 46
  • 2
  • 1
    while your answer might be entirely correct, it's always a good idea to try and see what OP has done first, we all have to put in some effort to solving our own problems, it isn't really a good idea to give out answers without OP at least posting some form of effort from their side – a_local_nobody Oct 03 '20 at 06:45
  • 1
    Your answer is correct but regex is faster and a much better approach. You should consider learning regex. – Alpha 1 Oct 03 '20 at 07:09
  • 2
    @AlphaOne I would say this is a really good answer though, regex may be better, but OP is quite newbie, so this is a good thinking approach for the OP. – Anunay Oct 03 '20 at 07:24
  • 1
    @Anunay Yes, that's a good answer. I already upvoted it. – Alpha 1 Oct 03 '20 at 07:29
  • 1
    Thank you very much for your support. This is my first try on Stach Overflow to answer as well as I can. @AlphaOne I never needed to learn regex, thanks to the community but I will surely learn it. Thank you! This made my day. – Jagan Oct 04 '20 at 14:48