Programming :: List String Indexes From An Array In Ksh?
Jan 24, 2011How can I list string indexes from an array in ksh ?
View 4 RepliesHow can I list string indexes from an array in ksh ?
View 4 RepliesHow can i split a string like this,
Code:
This is my first line.
This is my second line.
This is my third line.
into,
Code:
"This is my first line.", "This is my second line.", "This is my third line."
in C++.
i.e. split the code at every new line
I've got a problem...
a[0] = 22
echo $[a[0]]
echoes 22 - that works fine
[code]...
I've searched around and can't find out how to convert a string ( like "12345" ) into an int array ( x[ 5 ] = { 1, 2, 3, 4, 5 } ; ).
View 4 Replies View RelatedCan you create a dynamic string array and using calloc(),realloc()?
Like:
Code:
string* x;
x = (string) calloc(x,sizeof(string));
I am using gnu bash 3.2I need to split the string into array like
a=this_is_whole_world.file # split [_.]
I need to split this on _ and . some thing like this
a[0]=this
a[1]=is
a[2]=whole
a[3]=world
a[4]=file
preferable using bash regex. if not sed is also ok.
I need to call a function that takes a string array as argument, declared like this:Code:int someFunction(/* some parameters... */, const char* s[]);I'd like to know how to allocate memory for the string array. I know a string is an array of chars and an array is a pointer to the first element, then a string array should simply be a two dimensional char array. But is it a single memory block where all strings are stored consecutively?? Or is it a base vector where each element is a pointer to a separate memory block that contains a single string?More specifically: should I malloc() a single memory block large enough for all the strings? or should I allocate separate blocks for each string plus an extra one for the base vector?
View 5 Replies View Relatedi have problem in java. how to convert string array to character. e.g string a[]={"ab","abc","abd","ag"}; what will be the character array ?
View 3 Replies View RelatedI have the following function that does not iterate through the array I want to be able to do some manipulation on each element in the array[@].it appears the below array has only one item in the array whereas i want the array to have 3 items hence the loop three times printing the message Any ideas why this is not happening ?
function foo() {
name =$1
array=( "$2" )
[code]...
Please look at the comments
Code:
/*
* TEST CASE TO CHECK DIFFERENCES BETWEEN STRING AS
[code]...
I want to put a string, such as the one found in the image, into an array that will later be chopped into individual words and put into another array of individual words found in the initial string. (or, perhaps, I would be able to do that initially, but for now, that is the goal)My question is, how can I do that without using quotation marks?
View 5 Replies View RelatedI have a sed match that matches for certain string of a regex expression:
Code:
tname=$(echo "$contents" | sed -n 'some pattern')
How do I match for multiple strings in the $contents and return them as an array? for example
Code:
contents="this is a text, just to match patterns, here is another text to be matched"
the sed func would be able to recognize both "text"s, but only one is outputted?
Possible to put it in an array? so ${bar[0]} gives one and ${bar[1]} gives another
This may be a basic bash array/string operation related question, but I couldn't find any direct answer. So here it goes:I have a lot of data sorted in various directories. All directories need same processing except for a special group of directories. I have a symbolic link of the script in discussion in each directory. I want the script to get the name of the current directory, check if that belongs to special group and do specific operations.So I get the name of the directory
Code:
mm=`basename `pwd``
Now the the group of directories that needs something different to be done, contains these
[code]...
Here is the issue. I am reading in a outside text file and putting in the string on that line into a char array that is already allocated.
Code:
int main(int argc, char *argv[])
{
[code]....
I am trying to create an array that will allow me to print a list after selection such as:
1) Location A
2) Location B
3) Location C
Would you like to print selected locations? Print I have no idea how to approach this problem and don't know whether Perl, Bash or shell script would be the most useful in this particular situation.
How to list all the files that don't contain pattern1 and append a new line (pattern1) to those files before pattern2 only once.
pattern1 = /var/script/showMessage.sh
pattern2 = ;;
Code:
grep -c 'pattern1' /var/script/*_cam* | grep :0 | add pattern1 before pattern2 in each file loacted before.
explanation what I want to do exactly:I have a textfile which looks for instance like this:
file.txt:
...
something=else to do
[code]....
copy string a to string b and change string b with toupper() and count the chars
View 3 Replies View RelatedI'm brand new to ubuntu I had an old laptop and a friend gave me a ubuntu version 8 I think instal disk and I'm trying to install from the add/remove applications it will usually get to about 44 then stop and come up the message "could not download all repository indexes". I can't even get the current list of applications.
View 1 Replies View RelatedThe below snippet works fine until I use strict. Then it dies with the following error: uote:Can't use string ("html") as an ARRAY ref while "strict refs" in use at ./filetest3 line 18.I want to create @lists based on the $scalars in @type. However, "my @$ext = ()"; and push (@$ext, @files); do not play nice with strict. How do I get around this?Quote:
#!/usr/bin/perl -w
system clear;
use strict;
[code]...
how do I split a string into an array?In this string:"this is a story"how do I split it by the space?
View 8 Replies View RelatedI've been trying to understand pthread in C a little better. So I made a simple program that takes in a string from the command line and creates a thread to print the string. I've looked online and copied the basic concepts but there are something things I'm confused about. The programs works just fine, but I have questions. Here's what I have so far.
[Code]....
One thing I'd like to know is why the 3rd argument in the pthread_create function which is my SendMessage function needs to be typecasted to a void pointer and then send the address of the function. Also as for the 4th argument, I would see typecasting to void pointer in some of the pthread examples I saw online, but in my case I'm passing a char pointer, would this be correct? In which case would I ever want to pass a void pointer?
Do I need a pthread_exit(NULL) in my main and in the SendMessage function? If so, why? I added the sleep() function so that I could let the pthread_exit function in my SendMessage function execute first. I simply saw that the online examples on pthread had pthread_exit() in both locations.
I am trying to dynamically delete and add information into the array "blah"
Code:
int blahsize = 1;
char** blah = (char**) calloc(blahsize+1,sizeof(char*));
Adding information:
Code:
blah[1]=stuff1;
blah[2]=stuff2;
code....
I have trouble converting a short array to a char array
Code:
short pShort[4] = { 0x41, 0x42, 0x43, 0x44 };
How to convert this to a char array?
I have a set of lines as ahown below:
Leon went to school
Leon came back from school..
Leon had dinner...
I have to replace the line containing "dinner" by a single string LUNCH...
I need to creates string suffixes out of a Reference string. for eg. suffixes of abcdefg will be
1)bcdefg
2)cdefg
3)defg
and so on...
create an array of pointers to point to the first few characters and then use that pointer to print the rest of the string.But when i print using the pointer i get GARBAGE values! shudn't std::cout<<ptr[w] print the string following the char it is pointing to? why do i get garbage values?
So if I'm given a location of a file like:
How can I just take the type of the file at the end? I know I can use strrchr() for a period to get the pointer to the period just before file type. Is there a build in string function that will just take the rest of the string from a certain point on forward in the string? I know it wouldn't be much work to make it myself, but I figured I would find out if it already existed before doing it.
Code:
The error is:
Code:
What I want to do is take input of ip4 as a string, convert it to an integer to add 1 to it, then reconvert it back to a string. Its not working.
My full code is:
Code:
I'm writing a PHP program. I've encountered a problem; in the following code I try to pass $_POST['delete'] which is an array as the value of a hidden input to some form, but it doesn't do so.there's something wrong with converting PHP array into HTML array. I'm sure that $_POST['delete'] is not null and is a real array.
echo '<input type="hidden" name="delete[]" value="'.$_POST['delete'].'" />';
Code: Select allmyusername@mycompname:~$ varCurl="abc def curl: ( xyz asdf"
myusername@mycompname:~$ expr index '$varCurl' "curl: ("
4
myusername@mycompname:~$ expr index "$varCurl" "curl: ("
3
myusername@mycompname:~$ echo $varCurl
abc def curl: ( xyz asdf
How to make sure that space is treated as space and string is not treated as array? (I expect value of 9 or 10, not 3 or 4).