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

Home Posts Topics Members FAQ

removing whitespaces from middle

9 New Member
i was wondering how would u remove multiple whitespaces from the middle of a string to make it only one white space...for example:

Expand|Select|Wrap|Line Numbers
  1. string hi= "hi     bye";
then remove the multiple whitespaces in middle to make it "hi bye"

any help would be appreciated...t hanks.
Apr 6 '07 #1
5 2320
jj555s
36 New Member
I'm not sure if your example shows multiple whitespace. But, you can try detecting for sequential whitespaces, if true, I forgot which function would work best, strcpy, substr?

for x = 0; x < strlen (of string); x++)
if gkfghjk[x] == ' ';
if fgjfjfghjfj[x+1] == ' ';
here you do something
Apr 6 '07 #2
mishink7
9 New Member
yeah my example didnt show it for some reason...i tried substr, but i couldnt get it to work for some reason.
Apr 6 '07 #3
mishink7
9 New Member
i tried something like this, but its not working

string trim3(string s)
{
int i=0;
while(i < s.size())
{
if (isspace(s[i]))
{
int p=0;
while (isspace(s[i]))
{
p++;
i++;
}
s.erase(i, p);
}
++i;
}
return s;
}
Apr 6 '07 #4
mishink7
9 New Member
ok im trying it the way you told me now...i almost got it i think
Apr 6 '07 #5
mishink7
9 New Member
thanks a ton...it worked.
Apr 6 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2351
by: Mar Thomas | last post by:
I have a dom tree created from an XML document but it shows whitespaces as Textnodes!! Pls tell me how to get rid of them I tried ... factory.setIgnoringElementContentWhitespace(true); but it doesnt work! Help me please thanks
0
1311
by: Prawdziwa Blondynka | last post by:
Hi, I would like to do the following with C++ and Xerces: set the schema path in an XML file to parse in this way: XMLCh* schemaLocation = XMLString::transcode(namespaceAndPath); //namespaceAndPath stands for the namespace and schema path containing whitespaces parser->setProperty(XMLUni::fgXercesSchemaExternalSchemaLocation,
2
4727
by: vsgdp | last post by:
From what I learned, if you want to do random element insertions and deletions you should use a list. But, with std::vector, if the order of the elements does not matter, couldn't you efficiently remove a random element by swapping it with the last element and then just using pop_back? Does erase do this internally? Or does erase do the element shift to fill in the gap?
1
1697
by: rj | last post by:
Hello, I try to remove whitespaces from a string using the preg_replace function like preg_replace("/*/"," ",$string); This works great, but makes no handles all characters in the same way. I want to preserve data between double quotes. So, hello world "It is a sunny... world"
7
1747
by: Adam Honek | last post by:
Is there a direct way to remove one entry from a one dimensional array? I keep looking but either my eyes are funny or it isn't there. Must we really create a temp array and copy all but 1 of the entries over to delete one entry? All I want to do is remove an entry at a specified index and then have the ubound(array) go down -1.
2
1679
by: rn5a | last post by:
When a Button is clicked in a Form, the JavaScript 'prompt' dialog pops-up for users to enter any text. When the user clicks OK in the prompt dialog, the text is populated in a TextBox & the Form posts. I then retrieve the text using Request.Form. The problem I am facing is in retaining whitespaces in the text the user has entered. Assume that the user has entered the following text in the JavaScript prompt dialog (note the whitespaces...
7
2826
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds to support cloning: Public Class RefClass Public tcp As TcpClient Public name As String End Class Public Class RefClassList Inherits List(Of RefClass) Implements ICloneable
9
2665
by: Saravanan Krishnan | last post by:
Hi, i'm writting a windows application in C# the functionality that i'm trying is to implement is to add items to a combo box at run time & when i select one item, my app should filter the list contents based on the selection i made in the combo box. I'm able to add items to combo box and also filter the list contents. But the only trouble i'm facing is when i select a item with a whitespace in the middle of a string in the conbo box, it does...
20
2942
omerbutt
by: omerbutt | last post by:
hi there i am making an application in which i have to populate columns that consist of some textfields and some input boxes the problem is at the mozilla's end, it creates a new node and appends the new created or child node to the parent node it is working fine to the point of addition in the Explorer And Mozzila but when it comes to deleting the column it still works perfect in explorer without any javascript or other error but when i try to...
0
8394
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
8306
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
8825
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...
1
8503
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,...
1
6164
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
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
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.