10-17-2002
Accessing substrings by offset and length
Hi,
I have a simple question... In C do we have a standard library function which will return the pointer to a substring at certain offset and having certain length...
Ofcourse we should take care not to access beyond allocated length in the parent string and don't overwrite beyond allocated length in the destination string...
it may look like this
int foo (char *s, char *t, int offset, int length);
if *s = "vishnu"; offset = 3; length = 2; it should give back
*t = "sh"
I'm not saying I want a function with the exact interface as above, but anything which allows me to access substrings by offset and length would be great...
This is not a homework question!!! I work in an office and write small C programs and sh scripts to automate task in a UNIX environment..
Thank you!
Vishnu.
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Is there a command that sets a variable length?
I have a input of a variable length field but my output for that field needs to be set to 32 char.
Is there such a command?
I am on a sun box running ksh
Thanks (2 Replies)
Discussion started by: r1500
2 Replies
2. UNIX for Dummies Questions & Answers
Hi ,
I have a peculiar case, where my sed command is working on a file which contains lines of small length.
sed "s/XYZ:1/XYZ:3/g" abc.txt > xyz.txt
when abc.txt contains lines of small length(currently around 80 chars) , this sed command is working fine.
when abc.txt contains lines of... (3 Replies)
Discussion started by: thanuman
3 Replies
3. UNIX for Dummies Questions & Answers
I want to find out the record length of a fixed length file? I forgot the command. Any body know? (9 Replies)
Discussion started by: tranq01
9 Replies
4. Shell Programming and Scripting
Hi guys,
I am stuck in this problem. Please help.
I have two files.
FILE1 (with records starting from '>' )
>TC1723_3 similar to Scific_A7Q9Q3
EMSPSQDYCDDYFKLTYPCTAGAQYYGRGALPVYWNYNYGAIGEALKLDLLNHPEYIEQN
ATMAFQAAIWRWMNPMKKGQPSAHDAFVGNWKP
>TC214_2 similar to Quiet_Ref100_Q8W2B2 Cluster;... (1 Reply)
Discussion started by: smriti_shridhar
1 Replies
5. Shell Programming and Scripting
Hi,
I'm looking for a way (other than C) to pull out a number of bytes in a Linux file for a giving length. for example:
file1 contains 2 records:
abcdefghijkl
mnopqrstuv
.....
so, I want to pull starting in byte 9 for a length of 8
file2 would contain:
ijkmnopq
Thanks (2 Replies)
Discussion started by: jbt828
2 Replies
6. Shell Programming and Scripting
Hello Everyone,
I am stuck with one issue while working on abstract flat file which i have to use as input and load data to table.
Input Data-
------ ------------------------ ---- -----------------
WFI001 Xxxxxx Control Work Item A Number of Records
------ ------------------------... (5 Replies)
Discussion started by: sonali.s.more
5 Replies
7. Shell Programming and Scripting
I have a string like
Months=jan feb mar april x y ..
Here the number of fields in Months is not definite
I need to extract each field in the Months string and pass it to awk . Don't want to use for in since it is a loop . How can i do it (2 Replies)
Discussion started by: Nevergivup
2 Replies
8. UNIX for Advanced & Expert Users
Hi,
I am trying to get the position of a repeated string in a line using
grep -b -o "pattern"
In my server I am using GNU grep version 2.14 and the code is working fine. However when I am deploying the same code in a different server which is using GNU grep version 2.5.1 the code is not... (3 Replies)
Discussion started by: Subhamoy
3 Replies
9. Shell Programming and Scripting
Hello gurus,
I have a lookup table
cat tmp1
\\\erw``~ 1
^774574574565665f\] 2
()42543^
and I`m trying to compare a bunch of strings such that, either the lookup table column 1, or the string to be looked up are substrings of each other (and return the second lookup column if yes).
... (2 Replies)
Discussion started by: sheetalk
2 Replies
LEARN ABOUT REDHAT
xml::dom::characterdata
CHARACTERDATA(1) User Contributed Perl Documentation CHARACTERDATA(1)
NAME
XML::DOM::CharacterData - Common interface for Text, CDATASections and Comments
DESCRIPTION
XML::DOM::CharacterData extends XML::DOM::Node
The CharacterData interface extends Node with a set of attributes and methods for accessing character data in the DOM. For clarity this set
is defined here rather than on each object that uses these attributes and methods. No DOM objects correspond directly to CharacterData,
though Text, Comment and CDATASection do inherit the interface from it. All offsets in this interface start from 0.
METHODS
getData and setData (data)
The character data of the node that implements this interface. The DOM implementation may not put arbitrary limits on the amount of
data that may be stored in a CharacterData node. However, implementation limits may mean that the entirety of a node's data may not fit
into a single DOMString. In such cases, the user may call substringData to retrieve the data in appropriately sized pieces.
getLength
The number of characters that are available through data and the substringData method below. This may have the value zero, i.e., Char-
acterData nodes may be empty.
substringData (offset, count)
Extracts a range of data from the node.
Parameters:
offset Start offset of substring to extract.
count The number of characters to extract.
Return Value: The specified substring. If the sum of offset and count exceeds the length, then all characters to the end of the data
are returned.
appendData (str)
Appends the string to the end of the character data of the node. Upon success, data provides access to the concatenation of data and
the DOMString specified.
insertData (offset, arg)
Inserts a string at the specified character offset.
Parameters:
offset The character offset at which to insert.
arg The DOMString to insert.
deleteData (offset, count)
Removes a range of characters from the node. Upon success, data and length reflect the change. If the sum of offset and count exceeds
length then all characters from offset to the end of the data are deleted.
Parameters:
offset The offset from which to remove characters.
count The number of characters to delete.
replaceData (offset, count, arg)
Replaces the characters starting at the specified character offset with the specified string.
Parameters:
offset The offset from which to start replacing.
count The number of characters to replace.
arg The DOMString with which the range must be replaced.
If the sum of offset and count exceeds length, then all characters to the end of the data are replaced (i.e., the effect is the same as
a remove method call with the same range, followed by an append method invocation).
perl v5.8.0 2000-01-31 CHARACTERDATA(1)