Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > problem with removing spaces in the string

Reply
Thread Tools

problem with removing spaces in the string

 
 
runner
Guest
Posts: n/a
 
      09-20-2007

"ramu" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Hi,
>
> Suppose I have a string like this:
>
> "I have a string \"and a inner string\\\" I want to remove space in
> this string but not in the inner string"
>
> In the above string I have to remove spaces, but not in the inner
> string(\"and a inner string\\\"). Will anyone please tell me how to do
> this?


If you still haven't found a solution, please write:

1) A sample string, as typed by the user.
2) The same string, according to the C syntax.
3) The processed string, in C syntax.
4) The processed string, as written to the console.

Do you confirm that the START of the *inner string*
is marked by \" ?

Do you confirm that the END of the *inner string*
is marked by \" ?

Or what?



 
Reply With Quote
 
 
 
 
Thad Smith
Guest
Posts: n/a
 
      09-21-2007
ramu wrote:
> On Sep 19, 2:13 pm, (E-Mail Removed)-cnrc.gc.ca (Walter Roberson)
> wrote:
>> In article <(E-Mail Removed). com>,
>>
>> ramu <(E-Mail Removed)> wrote:
>>> Suppose I have a string like this:
>>> "I have a string \"and a inner string\\\" I want to remove space in
>>> this string but not in the inner string"
>>> In the above string I have to remove spaces, but not in the inner
>>> string(\"and a inner string\\\"). Will anyone please tell me how to do
>>> this?

>> Incomplete specification.
>> - Do inner strings nest?
>> - why is the ending delimeter for the inner string \\\" instead
>> of \" ? What should happen if a \" appears in the inner string?
>> --
>> Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson

>
> No. inner strings do not nest. But inner strings can contain one or
> more double quote and/or one or more back slash.
> The delimiter is double quote and \\ is the part of the inner
> string.
>
> The user input might be like this:
>
> "I have a string "\\" I want to remove space in
> this "string but not in the" "\"" inner string"


I assume that an inner string has the same syntax as a C string literal.
If not, please show exactly how they differ. If so, then the inner
string may represent \ and " characters by escaping them with the
sequences \\ and \". It is important to note that within string
literals a series of \s are paired:
"\\\\"
is a string literal containing \\, not the beginning of one containing
an escaped quote.

I try here to separate the actual characters in an array with the
representation as a string literal.

Start with
<string>the "bad" boys</string>
having 14 characters, where <string> and </string> are the delimiters of
a sequence of characters (to reduce confusion).

C string literal (which is a string of characters) containing those
characters:
<string>"the \"bad\" boys"</string>
has 18 characters.

A character string containing the above string literal:
<string>I saw "the \"bad\" boys" yesterday.</string>

If you give that string as input to your program, I assume you want the
output to be
<string>Isaw"the \"bad\" boys"yesterday.</string>,
but without the outside delimiters.

You could read the input string shown above, without the outside
delimiters, from an input stream.

If you wanted to represent the input as a string literal for testing,
you would code
char s[] = "I saw \"the \\\"bad\\\" boys\" yesterday.";

Your earlier example:
char s[] = "I have a string \"\\\" I want to remove space in this
string but not in the \"inner string\" ";

is a representation of the character sequence
<string>I have a string "\" I want to remove space in this
string but not in the "inner string" </string>

Using my assumed definition of inner string, the inner strings are
<string>\" I want to remove space in this string but not in the </string>
and the unterminated inner string
<string> </string>
at the very end of the subject string.

Is that what you intend?

--
Thad
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[CSS] how can I show spaces as spaces? Tomasz Chmielewski HTML 21 09-10-2009 06:43 PM
how can I show spaces as spaces, part 2 Tomasz Chmielewski HTML 14 09-10-2009 03:54 PM
Re: How to trim a String trailing spaces, but not leading spaces? Roedy Green Java 3 09-14-2008 02:10 AM
Re: How to trim a String trailing spaces, but not leading spaces? John B. Matthews Java 4 09-12-2008 05:28 AM
How can I search and replace a string while preserving (not removing) trailing spaces? rsarpi Perl Misc 1 05-13-2007 04:29 AM



Advertisments