473,657 Members | 2,572 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

removing spaces in a string

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.";

when i step through this the variable plain text looks like this:
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.

so when i go to print it displays as it is above...not pretty!

However if i declare plaintext in this fashion:

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.";

(in an editor it would appear on one line) there are no gaps in
plaintext.

how can i use the line break "\" for aesthetics in the editor and not
have the spaces or how do i remove the spaces.

Also i am trying to print plaintext with no more than 60 characters
per line and no word can be broken when starting a new line.

example:

on printing the word liberty if it happens to exceed 60 characters at
the "b" then the entire word needs to be printed on the next line.

hope all this is clear.

Thanks,

Lino

Nov 17 '05 #1
3 2822
lino wrote:
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.";

when i step through this the variable plain text looks like this:
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.

so when i go to print it displays as it is above...not pretty!

However if i declare plaintext in this fashion:

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.";

(in an editor it would appear on one line) there are no gaps in
plaintext.

how can i use the line break "\" for aesthetics in the editor and not
have the spaces or how do i remove the spaces.


Write it like this:

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.";

Adjacent string literals are concatenated by the compiler into a single
string with no intervening newlines.

-cd
Nov 17 '05 #2
"lino" <li********@sbc global-dot-net.no-spam.invalid> wrote in message news:40******** **@127.0.0.1...
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.";


The modern, standard, way to make a string to span multiple lines
does NOT use backslash. Try this:

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.";

The max. string length limit still applies however.
--

Nov 17 '05 #3
An easy and economic way to do what you want to do is as follows

#define NUMBER_LINES

char * szBuffer[NUMBER_LINES]=
"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.
}

// The syntax is char * Buffer={"Line_0 "
"Line_1"
"Line_2"
"Line_3"}

// if the buffer is outseide a function use the pointe
// if the buffer is inside a function you don't need the pointe
/
BYTE function(void

BYTE i,limit

limit = NUMBER_LINES
i=0
do
cout << szBuffer[i]
cout << " " << endl
while (++ i < limit)

return (limit)

/
// The do{}while; inserts spaces and linefeeds after each Buffer's [Line
/
// To control the number of characters you show or print/line you coul
// use the same routine. But you would have to read from each line th
// number of characters you want to show or print into another buffe
// and then show of print this new buffer. This would call for some strin
// manipulation. Easier, would be to arrange your text from the start to
// the number of characters you want to print or show/line

James Sexto
Nov 17 '05 #4

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

Similar topics

9
6731
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 " "
6
6091
by: jalkadir | last post by:
I am trying to find a way to remove the leading and tailing blanks from a string. What I have come up with is not doing the work as I expected; because if the value I pass to the function is " string " the leading and trailing blanks are not removed. What am I doing wrong? trimIt( std::string s ) { size_t offset = s.length(); // Trim leading spaces ??? s.erase( 0, s.find_first_not_of( "\t\n" ) );
11
15002
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
3479
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
1791
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(
8
2497
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
7330
by: beatTheDevil | last post by:
Hey guys, As the title says I'm trying to make a regular expression (regex/regexp) for use in removing the comments from code. In this case, this particular regex is meant to match /* ... */ comments. I'm using Ruby v.1.8.6 Here's my regex: multiline_comments = /\/\*(.*?)\*\// When I try myStr.gsub(multiline_comments, "")
11
3059
by: ramu | last post by:
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?
2
10411
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
8326
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
8743
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
8522
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
8622
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...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2745
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1736
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.