473,671 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Split a line by whilespace or tabcharacter (\t)

21 New Member
Hi,

I have file in while following line are present

dir1 dir2 dir3 dir2 file1 file2
dir1_file1 dir1_file2\tdir 2_file1 dir2_file2\tdir 3_file1
...
...

reading a one line at a time from a file,

i'm using the function strtok_r() to split the each line with delimiter whilespace and '\t' character.

How can differentiate that 2 words are split by whitespace or '\t' character.

Is there any work around for this.
Plz let me know.

Thanks.
Sep 16 '11 #1
1 1744
weaknessforcats
9,208 Recognized Expert Moderator Expert
I wouldn't use strtok. Instead examine each character of your search string using isspace. That will detect whitespace and since \t is whitespace, it will be detected by default. Then extract your token using strncpy.
Sep 17 '11 #2

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

Similar topics

11
2161
by: David Morgenthaler | last post by:
How does one overide the iterator implied by the construct "for line in file:"? For example, suppose I have a file containing row,col pairs on each line, and I wish to write a subclass of file that will transform these to x,y coordinates using an affine transform. I'd like it to look something like this (but this clearly doesn't work): class myFile(file): def __init__(self,name,affine):
2
8056
by: mehul | last post by:
hi all, i am just starting with PERL and had this doubt related to the speical operator +. what it says is that in the line split( / +/,$line); it will not ignore the initial spaces as it starts a word when it encounters a space... so if possibly there is only a single space in the staring,then it shldnt be a problem isnt it? and also if there are more than 1 spaces then it says that also the word count would be 1 more than the total no...
7
17410
by: Alan Silver | last post by:
Hello, I have been having problems with some blindingly simple ASP that fails. I have the following code ... Dim sAds, sAdverts() sAds = "1" & vbTab & "Ferret" & vbTab & "Furry" & vbCrLf sAds = sAds & "2" & vbTab & "Gibbon" & vbTab & "HAiry" & vbCrLf sAds = sAds & "3" & vbTab & "Vole" & vbTab & "Small" & vbCrLf sAdverts = Split(sAds,vbCrLf)
5
4043
by: NewToThis | last post by:
I am trying to use the split function to bread up lines in a file I am reading from. Some lines are working just fine, but a couple of the lines don't split up the way I would have thought. Here's part of the code. Dim strDelim As String = "*~" Dim delimiter As Char() = strDelim.ToCharArray Dim split As String() = Nothing Dim fieldCount As Integer Dim s As String
4
3379
by: dchan1 | last post by:
String line = " I am new to c# "; How to use Regex to split the string so that It would return a String array with: token = "I" token = "am" token = "new" token = "to" token = "c#"
9
5523
by: acatejr | last post by:
I have a text file and each line is a list of values. The values are not delimited, but every four characters is a value. How do I get python to split this kind of data? Thanks.
2
3750
by: Shawn Minisall | last post by:
I'm trying to unpack a list of 5 floats from a list read from a file and python is telling me 5 variables are too many for the string.split statement. Anyone have any other idea's? NOTE: the only reason I convert it to a float instead of just leaving it as a string in the loop is because I have to have it printed out as a float besides the names and then the average displayed underneath thx #read in data line by line
11
21166
by: Horacius ReX | last post by:
Hi, I have to search for a string on a big file. Once this string is found, I would need to get the number of the line in which the string is located on the file. Do you know how if this is possible to do in python ? Thanks
4
1565
by: Gangreen | last post by:
Hi, I'm new to Perl but I have some experience in other languages. Anyway I need to split a string on the character "|". let's say our string is "one|two|three" when I try the following code: @fields = split('|' , $line); My line gets splitted into serperated letters instead of one two and three. Same when I replace '|' with /|/
5
11975
sicarie
by: sicarie | last post by:
I am attempting to parse a CSV, but am not allowed to install the CSV parsing module because of "security reasons" (what a joke), so I'm attempting to use 'split' to break up a comma-delimited file. My issue is that as soon as an "empty" field comes up (two commas in a row), split seems to think the line is done and goes to the next one. Everything I've read online says that split will return a null field, but I don't know how to get it to...
0
8401
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
8926
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
8824
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...
0
8673
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
7444
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
5703
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();...
0
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2060
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1815
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.