473,763 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with removing spaces in the string

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?

regards

Sep 19 '07
11 3068

"ramu" <ra******@gmail .comwrote in message
news:11******** **************@ 22g2000hsm.goog legroups.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?

Sep 20 '07 #11
ramu wrote:
On Sep 19, 2:13 pm, rober...@ibd.nr c-cnrc.gc.ca (Walter Roberson)
wrote:
>In article <1190217378.900 611.188...@22g2 000hsm.googlegr oups.com>,

ramu <ramu....@gmail .comwrote:
>>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(\"an d 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 <stringand </stringare 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"th e \"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
Sep 21 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
6736
by: hokiegal99 | last post by:
This script works as I expect, except for the last section. I want the last section to actually remove all spaces from the front and/or end of filenames. For example, a file that was named " test " would be renamed "test" (the 2 spaces before and after the filename removed). Any suggestions on how to do this? import os, re, string print " " print "--- Remove '%2f' From Filenames ---" print " "
11
15019
by: gopal srinivasan | last post by:
Hi, I have a text like this - "This is a message containing tabs and white spaces" Now this text contains tabs and white spaces. I want remove the tabs and white spaces(if it more than once between two words). Is there any function we have in C which will find out the tabs and white spaces and returns the text in the follwong way -
12
3496
by: Magix | last post by:
Hi, Everytime I received a fix-length of string, let say 15 (the unused portion will filled with Spaces before receive), I want to remove the Spaces from END until I encounter a non-space char. let say: testBuf is the buffer that receive this fix-length string. printf("",testBuf); Output:
1
1795
by: Mike in Paradise | last post by:
Is there a more effcient way of removing the spaces from the names for a Enumerated value that has several values when you split it)??? When you do a toString it puts ,<SPACE> between the entries eg. category.ToString() = "cat1, cat2, cat3" What I am currently doing..(and I use this a lot..) this.categoriesEntry.Items.AddRange(
3
2829
by: lino | last post by:
Hello, I have the following string: const char plaintext = "Fourscore and seven years ago our \ fathers brought forth upon this continent \ a new nation, conceived in liberty, and dedicated \ to the proposition that all men are created equal.";
4
1607
by: nik | last post by:
hello friends, i want to create a file and copy that file removing white spaces in the file; for ex a file : C:\\abcd.txt contents of file r: a b c d e. i want to remove white spaces from the file using skipws . how can i do this.
8
2507
by: starsky51 | last post by:
I'm sure it's something i'm doing wrong, I just can't see it. I've set up a simple page with the following code: <html> <head> <title>tester</title> <script language="javascript" type="text/javascript"> alert('First String Second String'); </script> </head>
2
6545
by: David | last post by:
Sent this to alt.php a couple of days back, but doesn't look like I'll get an answer, so trying here. I'm trying to convert a script to use friendly URLs, I've done this before, but my PHP skills are quite basic so far, far from proficient at this. ..htaccess file- DirectoryIndex default.php index.asp index.html index.htm index.php
2
10472
code green
by: code green | last post by:
I am trying to write a simple function that will take a string containing an address line or business name and return it nicely formatted. By this I mean extra spaces removed and words capitalised. I also wish it to be legal XML.. The result string is further sent to another function to check the names and addresses don't appear on a blacklist which is why the extra spaces need removing. This is my test function so far function...
0
9566
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9389
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10149
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10003
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9943
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9828
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8825
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5410
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3529
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.