OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

place hyphen between upper and lowercase text

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc
View previous topic :: View next topic  
Author Message
sarahnewby
Newbie
Newbie


Joined: 06 Jan 2010
Posts: 4

PostPosted: Wed Jan 06, 2010 8:15 am    Post subject: place hyphen between upper and lowercase text Reply with quote

Hi members
is it possible to place a hyphen with spaces on either side after the last uppercase word.
a sample of text would be
2 THIS IS MY_UPPERCASE TEXT4 This is not A sample
and the hypen should be placed as in this example.
2 THIS IS MY_UPPERCASE TEXT4 - This is not A sample
As in my example there may be numbers with a space or not before or after the uppercase text. There may be some grammer: e.g. , _ .
There are also capitals A or I amongst the lower case text so would probably need to be excluded as there wouldn't be many uppercase sentences ending in A or I.
Tried doing this using auto hotkey, but was not able to get it to ignore the single letter A or I.

Thanks Sarah
Back to top
View user's profile Send private message
jrkrideau
Super User
Super User


Joined: 08 Aug 2005
Posts: 6732
Location: Kingston ON Canada

PostPosted: Wed Jan 06, 2010 8:45 am    Post subject: Re: place hyphen between upper and lowercase text Reply with quote

sarahnewby wrote:
Hi members
is it possible to place a hyphen with spaces on either side after the last uppercase word.
a sample of text would be
2 THIS IS MY_UPPERCASE TEXT4 This is not A sample
and the hypen should be placed as in this example.
2 THIS IS MY_UPPERCASE TEXT4 - This is not A sample
As in my example there may be numbers with a space or not before or after the uppercase text. There may be some grammer: e.g. , _ .
There are also capitals A or I amongst the lower case text so would probably need to be excluded as there wouldn't be many uppercase sentences ending in A or I.
Tried doing this using auto hotkey, but was not able to get it to ignore the single letter A or I.

Thanks Sarah


Hi Sarah,
I don't know the answer to the problem but can I as a few questions?

First, am I correct in assuming that this is some kind of existing file?

What exactly is the auto hotkey? It's not a term I recognize. It sounds like you may have a macro running.

How long are the last words in capitals? Are they all more than one character ( excluding the posibility of a number)?

Can we reliably assume that the start of the uncapitalized text will be <space> capital letter, lowercase letter ?
_________________
jrkrideau
Kingston ON Canada
Currently using Windows 7 & OOo 3.4.0 and Ubuntu 12.04 & LibreOffice 3.5.2.2
Back to top
View user's profile Send private message
keme
Moderator
Moderator


Joined: 30 Aug 2004
Posts: 2910
Location: Egersund, Norway

PostPosted: Wed Jan 06, 2010 8:48 am    Post subject: Reply with quote

Edit - Find and replace.
Search for: ^([^a-z]*[:space:]+)*
Replace with : $0- .
Tick Match case
Select More options and tick Regular expressions
Replace all
Back to top
View user's profile Send private message
sarahnewby
Newbie
Newbie


Joined: 06 Jan 2010
Posts: 4

PostPosted: Wed Jan 06, 2010 10:14 am    Post subject: Reply with quote

jrkrideau
they are file names of existing files, and for the future file names i will copy and paste from a calc list.
I have thousands of existing files i need to rename as stated before, but will copy and paste the names of these files into calc, and after the list is modified copy and rename the files using Auto hotkey- which is very handy program for repetative windows tasks and is free.
even some of the coding looks similar to openoffice, when veiwing keme's code.


The sample i gave was probably the worst case scenario, except i forgot to add that sometimes there are lowercase letters amongst the uppercase.
e.g.
2 THIS IS a McUPPERCASE TEXT4 This is A sample

The majority of uppercase words would be more than 1 letter long, and some end with a number.
The best rules i could describe would be

if the last capital word before a lower case word ends with a number with no space then hyphen would be placed as below

2 THIS IS MY_UPPERCASE TEXT4 - This is not A sample

if the last capital word before a lower case word is followed with a space then a number then the hyphen would be placed as below

2 THIS IS MY_UPPERCASE TEXT - 4 This is A sample

if there are single capital word like the letter A or I or U- among the lowercase words which seem to be the majority of them in my files,

2 THIS IS MY_UPPERCASE TEXT4 A is wrong I is wrOng
then hyphen would be placed as below

2 THIS IS MY_UPPERCASE TEXT4 - A is wrong I is wrOng

more often then not in my files the uppercase words do not end with a single uppercase letter, but many are amongst the lowercase words. which the majority of those are A, I, O, U.

There is always a space between the upper and lowercase words, but the lowercase word start either with a upper or lowercase text e.g.

2 THIS IS MY_UPPERCASE TEXT4 This is A sample

2 THIS IS MY_UPPERCASE TEXT4 this is A sample

Thanks Sarah.
Back to top
View user's profile Send private message
sarahnewby
Newbie
Newbie


Joined: 06 Jan 2010
Posts: 4

PostPosted: Wed Jan 06, 2010 10:30 am    Post subject: Reply with quote

keme
Your code works well, except i forgot to add that sometimes there are lowercase letters amongst the uppercase, see post above.
results are as below
2 THIS IS -a McUPPERCASE TEXT4 This is A sample
2 THIS IS -McUPPERCASE TEXT4 This is A sample

2 THIS IS UPPERCASE TEXT4 -This is A sample


Thanks Sarah.
Back to top
View user's profile Send private message
keme
Moderator
Moderator


Joined: 30 Aug 2004
Posts: 2910
Location: Egersund, Norway

PostPosted: Thu Jan 07, 2010 5:40 am    Post subject: Reply with quote

sarahnewby wrote:
keme
Your code works well, except i forgot to add that sometimes there are lowercase letters amongst the uppercase, see post above.
results are as below
2 THIS IS -a McUPPERCASE TEXT4 This is A sample
2 THIS IS -McUPPERCASE TEXT4 This is A sample

2 THIS IS UPPERCASE TEXT4 -This is A sample


Thanks Sarah.
OK. If your problem hasn't been resolved, there may be other ways to identify the split point. A stray upper-/lowercase character as a single word or within a word seems possible on both sides, which makes it difficult to use case as the splitting condition.

Is there a common pattern ending all of the "uppercase" strings, or starting all the "lowercase" ones (e.g.: a filename extension: period+3 letters ; all new names starting with the same exact term ; some part of the text always repeating)?
Back to top
View user's profile Send private message
sarahnewby
Newbie
Newbie


Joined: 06 Jan 2010
Posts: 4

PostPosted: Thu Jan 07, 2010 11:12 am    Post subject: Reply with quote

Hi ,
Have been trying to learn what is actually going on in the code. its doing my head in.

Answer to your ? is there is no pattern as you desribed.
The pattern the majority have is
UPPER space lower, within the uppercase there are some non text characters.
when looking down the row the majority of incorrect names were when there is a single capital letter e.g. I or A before a word that was either
THIS IS UPPERCASE TEXT I - This is A sample
THIS IS UPPERCASE TEXT I - this is A sample. The hyphen should be placed before the I.

I was thinking that it may be impossible to do this in 1 go,
So now the hyphens are added, I would then search for a space capital letter space then a hyphen e.g.
" I -" and replace as " - I", the majority of these are an I or A or U
seems to works and i suppose it could be automated.

The problem i have now is how to change the case to upper before the hyphen and lower after the hyphen.

The code is now
^([A-Z_!$', &^0-9Aacm]*[:space:]+)*

I dont know what im doing and trying to find simple explanation of regex is difficult.

I am trying to understand how the code above works.
Would i be correct that it can only look at individual characters and not whole words.
So it would go from the start of the string look at individual characters which in the code would be uppercase text A-Z including these characters _!$', & but ignoring ^0-9Aacm if they are in part of the word or as a single item.
The next part is difficult to understand *[:space:]+)*
My guess is it includes white spaces when it looks along the string, or only looks at the text either side of the white space.
The + * no clue to what they do, when reading the help file it states that the *
Finds zero or more of the characters in front of the "*".
So does this mean that in the above code that it finds all the characters in front of a space , and to the very end (decided by the search rules) in the brackets- indicated by the + being placed at the end of the code, but inside the brackets- and the second * placed at the end outside the brackets.

Keme, cute gif, i'm a little cross-eyed myself, caused by codeitis. (or by banging my head on the wall).
thanks sarah.
Back to top
View user's profile Send private message
keme
Moderator
Moderator


Joined: 30 Aug 2004
Posts: 2910
Location: Egersund, Norway

PostPosted: Thu Jan 07, 2010 2:07 pm    Post subject: Reply with quote

The hat (^) as the first character means "start of the line/paragraph", so we only find matches that belong to the "first half".
The hat inside the set means "not this", so "[^a-z]*" means "any number of characters (zero or more) that's not a lowercase letter".
The [:space:]+ means "one or more spaces".
I made a few tests. Originally I tried to specify allowable characters, so I needed to repeat the pattern. That's where the surrounding bracket and asterisk comes in. I don't believe it makes any difference with the current "negative set" of allowable characters.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group