-2

I am trying to find a way to extract text in a specific and efficient way as in this example:

'Hello Mr. Jack Andrew , your number is 894Gfsf , and your Bank ID # 734234"

I want a way to get the Name, the Number and the Bank ID Number.

I want to write software that deals with different text files and get those required values. I may not know the exact order but it must be a template like a bank statement or something.

Thanks!

Peter
  • 14,559
  • 35
  • 55
  • 1
    What did you try so far? – Dev-iL Sep 22 '14 at 13:01
  • Hello Dev_il , i Saw Many ways in this site but was not useful for my use, the last one was ( >> email = 'johndoe@hotmail.com' email = johndoe@hotmail.com >> email == '@' ans = Columns 1 through 13 0 0 0 0 0 0 0 1 0 0 0 0 0 Columns 14 through 19 0 0 0 0 0 0 , i tried to make email== name not char but i got **** sorry looks like not order text , here is the link http://stackoverflow.com/questions/1425147/finding-a-specific-character-in-a-string-in-matlab – Azzam Alrandi Sep 22 '14 at 13:08
  • This question is a bit too open ended, I think you should add some restrictions like if there is a template what is the actual format otherwise how will you discern a name from the other words? For example can you assume there is always a `.` before the name but nowhere else? – Dan Sep 22 '14 at 13:09
  • Dan Thank you For replying , Yes i guess it will be template , with Mr. or your account Number or whatever , the thing is there is a previous static word to indicate the value i need – Azzam Alrandi Sep 22 '14 at 13:10
  • 2
    Best practice on this site is to: ask specific programming questions, show previous effort and existing code, use proper highlighting and formatting, do not include chitchat or unnecessary formalities. – Cape Code Sep 22 '14 at 13:14
  • Thank you Jigg for your comment , still believe that the people in this site can help me – Azzam Alrandi Sep 22 '14 at 13:17

2 Answers2

1

It's a bit hard to understand what exactly is the problem.. If all you need to do is to split strings, here's a possible way to do it:

str = 'Hello Mr. Jack Andrew , your number is 894Gfsf , and your Bank ID # 734234';
tokenized = strsplit(str,' '); 
Name    = strjoin([tokenized(3:4)],' ');
Number  = tokenized{9};
Account = tokenized{end};

Alternatively, for splitting you could use regexp(...,'split') or regexp(...,'tokens');

Dev-iL
  • 23,742
  • 7
  • 57
  • 99
  • Dev_iL , Thank you for your time and kindness, I guess this may help especially because i have a template with specific order, Please can you illustrate the Regexp you wrote at the last line by an example – Azzam Alrandi Sep 22 '14 at 13:24
  • Please look at the reference page (linked in my answer) - MATLAB provides plenty of examples. – Dev-iL Sep 22 '14 at 13:25
  • Thank you so much for your help, I guess it's more than words can thank , Thank you – Azzam Alrandi Sep 22 '14 at 13:26
  • Why can't I tick Both answers ? – Azzam Alrandi Sep 22 '14 at 13:33
  • Okay Thank you so much , you answer me the same answer before , I will switch the tick every two days between you and him, so everyone is cool :P – Azzam Alrandi Sep 22 '14 at 13:38
  • Nah, don't mess with it. The upvote is fine, I don't care much about these "magic internet points". I'm glad you found the answers helpful. – Peter Sep 22 '14 at 14:30
1

I think you want regular expressions for this. Here's an example:

str = 'Hello Mr. Jack Andrew , your number is 894Gfsf , and your Bank ID # 734234';
matches=regexp(str, 'your number is (\w+).*Bank ID # (\d+)', 'tokens');

matches{1}
ans = 

    '894Gfsf'    '734234'

My suggestion would be to make a whole array of strings with sample patterns that you want to match, then build a set of regular expressions that collectively match all of your samples. Try each regexp in sequence until you find one that matches.

To do this, you will need to learn about regular expressions.

Peter
  • 14,559
  • 35
  • 55
  • Peter, Thank you for your attention and time , this could work two , my question can I use the same reqexp to abstract names ( strings ) ? – Azzam Alrandi Sep 22 '14 at 13:28
  • You need to edit the regexp to also capture the name. Like I say, you will need to understand how regexps work, and how to modify them for your own purposes. This is just a starting point. – Peter Sep 22 '14 at 13:30
  • Thank you so much, I will appreciate this , Best Regards – Azzam Alrandi Sep 22 '14 at 13:32