There is of course a dumb way to determine where an acronym is.
If you loop through the characters and then find a capital letter =A new
word starts.
While ( letter is capital && next_letter is capital too ) { add letter to
acronym }
There's a risk of having two adjacent acronyms - in this case, tough luck...
using System;
using System.Collections.Generic;
using System.Text;
namespace parsing
{
class Program
{
static void Main( string[] args )
{
string strOriginal = "ILoveMyPCButIDon'tLoveWindows2000";
string strResult = "";
bool bReadingNumber = false;
bool bReadingAcronym = false;
for( int i = 0; i < strOriginal.Length; i++ )
{
if( strOriginal[i] >= 'A' && strOriginal[i] <= 'Z' )
{
if( i 0 )
{
if( i + 1 < strOriginal.Length &&
( strOriginal[i + 1] >= 'A' && strOriginal[i +
1] <= 'Z' ) )
{
if( !bReadingAcronym )
{
bReadingAcronym = true;
strResult += ' ';
}
}
else
{
bReadingAcronym = false;
strResult += ' ';
}
}
bReadingNumber = false;
}
else if( strOriginal[i] >= '0' && strOriginal[i] <= '9' )
{
if( !bReadingNumber )
{
if( i 0 )
strResult += ' ';
bReadingNumber = true;
}
}
else
bReadingNumber = false;
strResult += strOriginal[i];
}
}
}
}
"Ashot Geodakov" <a_********@nospam.hotmail.comwrote in message
news:OO**************@TK2MSFTNGP03.phx.gbl...
So you want to determine where every word starts and pre-pend each word
with a space?
In your sample there is no clear way to separate words from each other.
You've got one acronym (PC), so the task is already quite complex. I
regret to inform you that in order to achieve this, you'll have to come up
with some artificially intelligent piece of software.
"Aamir Mahmood" <ab*****@efg.hijwrote in message
news:O%****************@TK2MSFTNGP04.phx.gbl...
>Hi,
I am looking for a routine (if someone has already written it), which can
convert the following string
"ILoveMyPCButIDon'tLoveWindows2000"
To
"I Love My PC But I Don't Love Windows 2000"
Didn't want to spend time if someone has already implemented it and wants
to share it.
If I don't find it I will write it.
Thanks.