I want to shorten the length of a string to 40 Elements. I did try it with length(), last(), first()... but in order to convert it into an array I need to know the content of the string. The String I want to shorten could have any value.
Would be cool if you can share similiar problems or have a solution.
I tried to convert the string into an Array, with the split() function but I dont know the 40th Element.
By using the length function I could find out the length of the String I want to shorten.
Maybe there is something to delete the last few Elements of the string but I dont know it.
substring(variables('String'),0,39)
This should solve your problem
Related
I need to iterate and parse 108 lines from a file and then sort them into 3 different hashes. (In one iterator.) (In Ruby)
I have the file loaded into the program and into the array I need to parse. When I try to make the iterator anyway I try to use the Regex Match command I get an error abut the unknown method. Is as simple that I can't use that method on a array?
lines = File.readlines('access_log')
lines.each.match(/^([:\d\.]+) .*\[.*\].*\"[A-Z]+ *(.+) HTTP/)
This and every other way I have tried to use the match method it hasn't worked.
This also doesn't anything for the hash, as I haven't done that yet.
/^([:\d\.]+) .*\[.*\].*\"[A-Z]+ *(.+) HTTP/.match(lines)
Have also tried this, but the error output appears that you cant run it on only the array. I beilive this is where I would need to tie the iterator in, but I'm stumped.
So, what's happening is that what readlines does is it slurps the entire text file.
So you have an array with the content of the textfile separated by a newline(and the newline is kept in every string in the array).
After that, you're doing lines.each, which brings out an enumerator. Then you're calling .match on the enumerator instead of the string itself
The proper way to do this would be
lines.each { |line| line.match(/^([:\d\.]+) .*\[.*\].*\"[A-Z]+ *(.+) HTTP/) }
However, the above actually won't do anything because all you're doing is iterating against each element and checking if it matches the REGEX.If you want it to actually do something, try...
matches = lines.map { |line| line.match(/^([:\d\.]+) .*\[.*\].*\"[A-Z]+ *(.+) HTTP/) }
Remember that the match method only works on strings. If match matches something, it returns an object of the class MatchData, else if it doesn't match anything-- nil.
This question already has answers here:
How to copy end of the Array in swift?
(6 answers)
Closed 6 years ago.
Swift's implementation of arrays is throwing me for a loop again! (Haw, haw.) All I want is to take an array of arbitrary length and get a new array (or an array slice) from it that has the first element removed.
Why is this so hard?
I just want to be able to do something like this:
let suffix = someArray.suffixFrom(1)
But I can't figure out how to do this. It seems the closest method I've found requires knowing the length of the array, which I don't know because it's computed inline and I really really hate having to split such a simple concept up into a bunch of variables and lines.
Elaboration:
I have a string split by colons (:) and I just want to create a Set containing all the :-delimited components excluding the first one.
So that a string "one:two:three" would return a set containing ["two", "three"]. Since I can create a Set from an array, all I really need is to get the suffix of the array, but I don't know how many components there are because it's inline:
return Set(attributeName?.componentsSeparatedByString(":").suffixFrom(1))
Why does Swift make this so hard?
Edit: Before a bunch of you suggest it, I'm well aware I could extend the array class to do this myself, but I'm writing a framework and I don't want to do that, and I also don't want to have to write a bloody utility function to do something so darned simple.
The CollectionType.dropFirst(_:) does exactly what you need, with the exact syntax you're looking for.
let suffix = someArray.dropFirst(1)
The question is quite simple but I can't find the answer.
I'm using j2me.
I have an integer array of 9 elements.
After all the computations now I want to print it or show it in a form.
It is something like Integer.toString(); for use with an array?
I know I can use a loop but I want to know if it's a faster way.
Use a loop but don't use the String + operator. Use StringBuffer.append().
This is/isn't homework...the printing of the list IS homework and that works great, the iscntrl() and Array stuff is 6 weeks from now stuff and giving me grief.
I want to create an array filled with the first 32 TLAs of the Ascii table so that when I print out a column / row chart of Decimal to Ascii code I can use iscntrl() to flag that it's an un-printable character. In its place I want to grab the next TLA in the array and print that instead of the non-graphical character.
I have the iscntrl() working fine. Just can't figure out the array thing. All the examples in the books I have and online want to demo grabbing input from the user and tossing it into the array. I want to give the array a list at the beginning in the code and pull from that.
Can someone either give me a good link for what I need or just tell me how to do the whole process?
I've got 32 three letter items and I need to populate the array and pull them out via a for loop.
Thanks.
You can declare an array like this, and pre-fill its values:
const char *ControlCharacterNames[] = {
"NUL",
"SOH",
"STX",
"ETX",
// etc
};
Then, you can access ControlCharacterNames as an array in your code.
http://publications.gbdirect.co.uk/c_book/chapter6/initialization.html, chapter "6.7.2. More initialization".
Long story short, you probably need something like
char *TLAs[] = { "TL1", "TL2", "TL3", "FYI", "WTH", /* ...and so on...*/ };
and then pull the one you need using it's index
printf(TLAs[3]); // print "FYI", the 4th TLA
Hope I understood your question right.
How do you save an array or an ArrayList in VB.NET using My.Settings? I cannot find the array type anywhere, even in the browse window.
I know I can convert the array to a string, but I do not know how to convert a string to an array. I know that if I were to break it at a delimiter then I could convert a string to an array, but my problem is that any text at all could be stored within the array as a single value, so I cannot pick a delimiter that is unlikely to be used.
I was also facing the same problem and I came up with a solution to this.
Here are the steps:
Open up the properties of your app and select settings
select the setting name and then where it says type click on the
arrow and select browse.
in the browse window type in system.collections.arraylist and hit enter!
there you have your array!
You can use array like this:
your_array_name(here_comes_the_item_no.) = whatever
What kind of array? I've had luck using StringCollection for strings. ArrayList works for most anything else (and that's about the only place I'd use arraylist).
I would either use the StringCollection type, and just convert your elements to/from strings when storing them in my.settings, or use XML Serialization to turn the array in to an xml string, and store that in my.settings.