I'm using an excel as my input. somebody combined a field (NAME) so that it has extra spaces between firstname and lastname. How can I eliminate them and output/print the name with just 1 space in between?
local stringvar first :=
Left ({@name}, instr ({@name}, " "-1 );
local stringvar last :=
Mid ({@name}, instrrev ({@name}, " "+1);
first + " " + last
Hope this helps Christine
Crystal Training and Consulting
crosenbaum@Strafford.com
StringVar Text := "John Smith";
Left (Text, Instr(text, " "-1) + right (Text, InStrRev(Text, " "-1)
You can of course comment out the first line and change the word 'Text' into the name of your field.
This formula will only work if NAME has only two names in it e.g. First Name and Last Name. If it has other things like Titles then it won't work.
It works by combining the Left word in NAME (i.e. up to the first space) with a single space, followed by the Last word in NAME (i.e everything following the last space).
Strictly speaking - this post should have appeared under formula help. Hope it works for you.
Steve Phillips, Crystal Consultant
It might be easier to go to Excel and replace a double space " " with a single space " " globally for that column.
Go to the edit menu and choose "replace". This takes about 3 seconds.
Of course if this is on ongoing issue, thats another story. Software Training and Support for Macola, Crystal Reports and Goldmine
714-348-0964
dgilsdorf@mchsi.com
thank u all guys. I appreciate all the replies. But here's the good news: I was researching on the original excel file if there is a function that will eliminate the extra spaces in a cell. And lo and behold!
=trim(cell) will do the trick
This works even if there is a Title or middle initial in the field.
it's not the prettiest, but if you build a formula with the following expression, replacing all of the periods with spaces (I used periods so you could see them) then it will show each occurance of multiple spaces as a single space. I think this will work for strings with up to 2,447 consecutive spaces.
REPLACE ALL event2 WITH replacestring(replacestring(replacestring(replacestring(replacestring(replacestring(fmlMyField,'................','.'),'........','.'),'....','.'),'..','.'),'..','.'),'..','.')
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.