Guys,
I'm currently trying to extract a name from an email address. For example I have example.a.example@examplecompany.com. I have easily been able to get to example.a.example but I'm toying with the best way of converting it to Example A Example. The problem I have is that some email addresses will have 2 dots and some will have 1 and some may not have a dot at all.
If any of you have hit something similar and could pass some pointers my way I would be grateful,
Jim.
String Handling Question
- jim wood
- Site Admin
- Posts: 3961
- Joined: Wed May 14, 2008 1:51 pm
- OLAP Product: TM1
- Version: PA 2.0.7
- Excel Version: Office 365
- Location: 37 East 18th Street New York
- Contact:
String Handling Question
Struggling through the quagmire of life to reach the other side of who knows where.
Go Build a PC
Jimbo PC Builds on YouTube
OS: Mac OS 11 PA Version: 2.0.7
Go Build a PC
Jimbo PC Builds on YouTube
OS: Mac OS 11 PA Version: 2.0.7
- jim wood
- Site Admin
- Posts: 3961
- Joined: Wed May 14, 2008 1:51 pm
- OLAP Product: TM1
- Version: PA 2.0.7
- Excel Version: Office 365
- Location: 37 East 18th Street New York
- Contact:
Re: String Handling Question
I'm doing this in TI by the way, not rules. I'm looking in to using a while statement. If you hear an explosion from New York you know my toys have well and truely left the pram!!!
Struggling through the quagmire of life to reach the other side of who knows where.
Go Build a PC
Jimbo PC Builds on YouTube
OS: Mac OS 11 PA Version: 2.0.7
Go Build a PC
Jimbo PC Builds on YouTube
OS: Mac OS 11 PA Version: 2.0.7
-
- Site Admin
- Posts: 6667
- Joined: Sun May 11, 2008 2:30 am
- OLAP Product: TM1
- Version: PA2.0.9.18 Classic NO PAW!
- Excel Version: 2013 and Office 365
- Location: Sydney, Australia
- Contact:
Re: String Handling Question
A While loop is the easiest approach since there's no equivalent of Replace in TI. It's also the most flexible as you can have an If block which checks for the period (or any other character that you may want to check for in future) and replace it with a space. A combination of the Long function to get the length of the string, the While function and Subst function to pull out each character as you iterate through the string length (and also Code, if you want to check for unusual characters) and bang, you're done.jim wood wrote: I'm currently trying to extract a name from an email address. For example I have example.a.example@examplecompany.com. I have easily been able to get to example.a.example but I'm toying with the best way of converting it to Example A Example. The problem I have is that some email addresses will have 2 dots and some will have 1 and some may not have a dot at all.
I'm doing this in TI by the way, not rules. I'm looking in to using a while statement. If you hear an explosion from New York you know my toys have well and truely left the pram!!!
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
-
- Posts: 81
- Joined: Tue May 31, 2011 6:29 am
- OLAP Product: TM1 and EV
- Version: 9.1 SP3
- Excel Version: Excel 2010
Re: String Handling Question
You could try this:
myStrLen=SCAN('@',v1)-1;
myStr=SUBST(v1, 1, myStrLen);
myCharIndex = 1;
myFinalString='';
# test for '.' or ' ' then goto next char
While(myCharIndex<=myStrLen);
mystring=SUBST(myStr, myCharIndex, 1);
if(myString@='.' % mystring@= ' ');
myCharIndex = myCharIndex + 1;
mystring=SUBST(myStr, myCharIndex, 1);
myFinalString=myFinalString|' '|myString;
else;
mystring=SUBST(myStr, myCharIndex, 1);
myFinalString=myFinalString|myString;
endif;
myCharIndex = myCharIndex + 1;
end;
outputStr=myFinalString;
# capitalise strings
emailString=CAPIT(outputStr);
then you would need to concatenate the remainder of the string after emailString to get the result.
Cheers
Zark
myStrLen=SCAN('@',v1)-1;
myStr=SUBST(v1, 1, myStrLen);
myCharIndex = 1;
myFinalString='';
# test for '.' or ' ' then goto next char
While(myCharIndex<=myStrLen);
mystring=SUBST(myStr, myCharIndex, 1);
if(myString@='.' % mystring@= ' ');
myCharIndex = myCharIndex + 1;
mystring=SUBST(myStr, myCharIndex, 1);
myFinalString=myFinalString|' '|myString;
else;
mystring=SUBST(myStr, myCharIndex, 1);
myFinalString=myFinalString|myString;
endif;
myCharIndex = myCharIndex + 1;
end;
outputStr=myFinalString;
# capitalise strings
emailString=CAPIT(outputStr);
then you would need to concatenate the remainder of the string after emailString to get the result.
Cheers
Zark
-
- MVP
- Posts: 195
- Joined: Wed Jul 22, 2009 10:35 pm
- OLAP Product: TM1
- Version: 9.5.2 FP3
- Excel Version: 2010
Re: String Handling Question
You can also use Scan to find '.' (or ' ' or anything), just like you used it for finding '@'.
The loop will still be needed (you don't know the number of dots/spaces) but you do not need to iterate through whole string character by character (so it should work faster).
If Scan doesn't find the string it returns 0.
It would be nice to have a Replace/Substitute function, so you don't need to write a loop every time you need a substitution from one character to another.
The loop will still be needed (you don't know the number of dots/spaces) but you do not need to iterate through whole string character by character (so it should work faster).
If Scan doesn't find the string it returns 0.
It would be nice to have a Replace/Substitute function, so you don't need to write a loop every time you need a substitution from one character to another.
- jim wood
- Site Admin
- Posts: 3961
- Joined: Wed May 14, 2008 1:51 pm
- OLAP Product: TM1
- Version: PA 2.0.7
- Excel Version: Office 365
- Location: 37 East 18th Street New York
- Contact:
Re: String Handling Question
Thanks for all the input guys and thanks Zark for posting up some code for me,
Jim.
Jim.
Struggling through the quagmire of life to reach the other side of who knows where.
Go Build a PC
Jimbo PC Builds on YouTube
OS: Mac OS 11 PA Version: 2.0.7
Go Build a PC
Jimbo PC Builds on YouTube
OS: Mac OS 11 PA Version: 2.0.7