Hey i looked at some earlier discussions on this topic and they seem a bit complex i found this code example on another site - -
char str[] = "200.0.0.90-200.0.0.223";
-
-
char *first = strtok(str, "-");
-
-
char *second = strtok(NULL, "\0");
-
and i was wondering if it was possible to keep the delimiter in other words in this example the hyphen. Because in this example the hyphen is replace with a NULL and i need to keep the delimiter.
Thanks in advance, any help would be greatly appreciated.
6 2893
Why can't you use an array of string objects?? -
string arr[2];
-
arr[1] ="200.0.0.90";
-
arr[2] ="200.0.0.223";
-
char* strings are used in C. C++ programs should use STL string objects.
Let me explain it a bit better, i made a decimal to binary converter and with the final output if i used a small decimal number than i will get this 00000000001010 and i wanna chop of the zeros when it reaches one but keep the one.
Also i do use string bla; , for strings rather than char bla [8]; it just i'm trying to find a viable option for doing this.
Thanks in advanced
Have you tried using a bitset<> and a string ?? -
unsigned int data = 10;
-
bitset<32> bits(data); //convert data to 32 bits
-
string str = bits.to_string(); //convert the bits to char 1's and 0's
-
while (str[0] == '0') //remove leading '0'
-
{
-
str.erase(0,1);
-
}
-
cout << str << endl;
-
Or, you can just do this: - void chop(string& thisString)
-
{
-
while (thisString[0] == '0')
-
thisString = thisString.substr(1, thisString.length());
-
}
can then call it like this, if bla is your string:
chop(bla);
I thought of a method that would work faster, because it wouldn't involve a loop of function calls. - void binaryChop(string& thisString)
-
{
-
thisString = thisString.substr(thisString.find(‘1’), thisString.length());
-
}
this wouldn't even need to be a function.
sorry about the double post, but I couldn't edit my other one anymore.
Thanks for all the advice i will try them all and see which method works best, thanks again
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Mark Harrison |
last post by:
What is the best way to process a text file of delimited strings?
I've got a file where strings are quoted with at-signs, @like this@.
At-signs in the string are represented as doubled @@.
What's the most efficient way to process this? Failing all
else I will split the string into characters and use a FSM,
but it seems that's not very pythonesqe.
@rv@ 2 @db.locks@ @//depot/hello.txt@ @mh@ @mh@ 1 1 44
@pv@ 0 @db.changex@ 44 44 @mh@...
|
by: Aaron Walker |
last post by:
I have a feeling this going to end up being something so stupid, but
right now I'm confused as hell.
I'm trying to code a function, that given a string and a delimiter char,
returns a vector of the sub-strings.
Here's what I have (I've thrown a main() in there for this mail).
---
#include <iostream>
#include <string>
|
by: Dr. StrangeLove |
last post by:
Greetings,
Let say we want to split column 'list' in table lists
into separate rows using the comma as the delimiter.
Table lists
id list
1 aa,bbb,c
2 e,f,gggg,hh
3 ii,kk
4 m
|
by: fatted |
last post by:
I'm trying to write a function which splits a string (possibly multiple
times) on a particular character and returns the strings which has been
split. What I have below is kind of (oh dear!) printing the results I
expect, which I guess means my dynamic memory allocation is a mess.
Also, I was advised previously that I should really free memory in the
same place I declare it, but I'm not sure how I would go about doing
this
in my code...
|
by: Opettaja |
last post by:
I am new to c# and I am currently trying to make a program to retrieve
Battlefield 2 game stats from the gamespy servers. I have got it so I
can retrieve the data but I do not know how to cut up the data to
assign each value to its own variable. So right now I am just saving
the data to a txt file and when I look in the text file all the data is
there.
Not sure if this matters but when I open the text file in Word pad
(Rich Text) It...
| |
by: Fabian Steiner |
last post by:
I often have to deal with strings like "PCI:2:3.0" or "PCI:3.4:0" and
need the single numbers as tuple (2, 3, 0) or (3, 4, 0). Is there any
simple way to achieve this? So far I am using regular expressions but I
would like to avoid them ...
Regards,
Fabian Steiner
|
by: ronrsr |
last post by:
I'm trying to break up the result tuple into keyword phrases. The
keyword phrases are separated by a ; -- the split function is not
working the way I believe it should be. Can anyone see what I"m doing
wrong?
bests,
-rsr-
|
by: John |
last post by:
Hi
I have a multi-line address field which has each line separated by CRLF. How
can I split this field into individual strings using crlf as separator?
Thanks
Regards
|
by: shadow_ |
last post by:
Hi i m new at C and trying to write a parser and a string class.
Basicly program will read data from file and splits it into lines then
lines to words. i used strtok function for splitting data to lines it
worked quite well but srttok isnot working for multiple blank or
commas. Can strtok do this kind of splitting if it cant what should i
use .
Unal
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |