Question:
Need to count characters in text, then add word depending on length?
myrajaforever
2009-04-06 18:26:30 UTC
I have a list of 500 or so names one per line in flat text file, Am trying to add the word "Staff Member" after their name on a nametag. The tag can accommodate up to 30 Characters. So for that leave 18 characters (staff member is 12 chars) left for the name.

So i want to easily manipulate the data so if each name is less than 18 characters to append "staff Member" to the end, if its over 18 characters - just leave it.

how can i do this in word/excel/openoffice?

Thanks
Three answers:
Jallan
2009-04-08 13:33:33 UTC
“The tag can accommodate 30 members’'



This might be true if you are using a fixed-width font. If you are using a normal proportional font, then the number of characters that can be accommodated will vary. And on the average you will get more characters in the same space using a proportional font of the same height than you will with a fixed width font.



Your math is also wrong in that you have forgotten about the space (better two spaces) between name and title.

I suggest adding two spaces plus "Staff Member” to all your names. For the space in “Staff Member" use a hard space, You will find the hard space as U+00A0 (160) in the chart that comes up when you select Insert → Special Characters .... You can insert the character from that chart. This will make OpenOffice.org or Microsoft Office treat “Staff Member” as a single, unbreakable word.



In your mail merge, limit the line width on which you wish to print the name to the label width. You will probably also want to set the format to centering. Hide the line beneath under a blank box (frame) with no borders. If "Staff Member" won’t print on the first line because of lack of space, it will wrap down and under the blank box and will not appear. Or if you are only printing one line on the label, you can change the line spacing so that the 2nd line is outside of the label entirely, and will neither be seen nor be printed.



This will also work if for some reason you must use a fixed-width font on your label.



If you want to do it the way you were suggesting, look at the LEN function which gives the number of characters in a word.
potchie
2009-04-06 18:41:12 UTC
In excel, assuming the name is in column 1, you can use this:



=IF(LEN(TRIM(A1))<18,TRIM(A1)&" Staff Member",TRIM(A1))



I put trim there in case there are leading/trailing spaces in the field
Yahgoogle
2009-04-06 20:32:36 UTC
You can use Replace Pioneer to handle plain text directly.



Procedures:

1. ctrl-o open your text file



2. ctrl-h open replace dialog

* set "Replace Unit" to "Line"

* fill in "Replace with Pattern" window like:

${match}Staff Member\n

* fill in "if =>" window like:

length($match) <=18



3. click "Replace", done! Save to your target file.



Replace Pioneer free trial download:

http://www.mind-pioneer.com


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...