Range.Text - AllCaps problem

W

Walter Wang [MSFT]

Hi Dave,

If you're using VBA or VB 6.0, there's a function to convert a string to
proper case:

StrConv("dave", vbProperCase)


If you're using .NET, you could use TextInfo.ToTitleCase:

#How to convert strings to lower, upper, or title (Proper) case by using
Visual C#
http://support.microsoft.com/kb/312890


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Hi;

What I need is different. We have XPath text in the text here. So if the
original text is "/Root/DaVe" then we need it with exactly that casing. What
is interesting is a Find works for the actual casing of the text. But
Range.Text returns "/ROOT/DAVE"

I think ToTitleCase will do either "/Root/Dave" or leave it alone because of
the /.

Is there a way to get the actual text in the document?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
W

Walter Wang [MSFT]

Dave,

Would you please post more about the code, I want to reproduce it on my
side. Thanks.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Here is what I think is the relevant text (where the selected text is marked
ALL CAPS and is "<wr:eek:ut select='/root/node'/>"):
Selection sel = ThisApplication.Selection;
int _start = GetParagraph(sel.Paragraphs, 1).Range.Start;
int _end = GetParagraph(sel.Paragraphs, sel.Paragraphs.Count).Range.End;
Range rngStartTag = Find(_start, Math.Min(sel.Range.End + 3, _end), false,
"<wr:");
Range rngEnd = Find(rngStart.End, GetParagraph(rngStart.Paragraphs,
1).Range.End, true, ">");
object start = rngStart.Start;
object end = rngEnd.End;
rngTag = ThisDocument.Range(ref start, ref end);

rngTag.Text is returned as "<WR:OUT SELECT='/ROOT/NODE'/>"

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
W

Walter Wang [MSFT]

Hi Dave,

Thank you for your detailed explanation.

Based on my research, Range.Text will always return the text with the
effects applied to it. I didn't find a way to return the unmodified text.
To workaround the ALL CAPS effect, you could use following function:

private string GetRangeTextWithoutAllCaps(Range rng)
{
StringBuilder sb = new StringBuilder();
foreach (Range r in rng.Characters)
{
if (r.Font.AllCaps != 0)
{
r.Font.AllCaps = 0;
sb.Append(r.Text);
r.Font.AllCaps = -1;
}
else
{
sb.Append(r.Text);
}
}
return sb.ToString();
}


However, please note if other effects are applied to the text, such as
"hidden", you will also need to check it accordingly. In summary, the
Characters will return all characters of the Range regardless it's visible
or not, but if you want to retrieve the text in it, you will still need to
test if any effects are applied to it that may have affect on the returned
text. Based on my test, the ALL CAPS will change the case, the HIDDEN
effect will remove the text.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Walter Wang [MSFT]

Hi Dave,

I understand that only part of the selected text will be have ALL CAPS
effect turned on, that's why I do that character by character. Yes this
seems a little ugly since the performance might be slow for a large
selected text. Sorry I cannot find a better workaround.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Cindy M.

Hi Walter,
Based on my test, the ALL CAPS will change the case, the HIDDEN
effect will remove the text.
If you set the TextRetrievalMode to include Hidden text, that
might help with this problem.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17
2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top