up to first N characters
How do I get up to the first n characters of a string in java without doing a size check first(inline is acceptable) or risking an IndexOutOfBoundsException? ...
How do I get up to the first n characters of a string in java without doing a size check first(inline is acceptable) or risking an IndexOutOfBoundsException? ...
Hello I have this string: mystring = '14| "Preprocessor Frame Count Not Incrementing; Card: Motherboard, Port: 2"|minor' So I have 3 elements (id, message and level) divided by pipe ("|"). I want to get each element so I have written these little functions: def get_msg(i): x = i.split("|") return x[1].strip().repl...
To learn the basics of OCaml, I'm solving one of the easy facebook engineering puzzles using it. Essentially, I'd like to do something like the following Python code: some_str = some_str.strip() That is, I'd like to strip all of the whitespace from the beginning and the end. I don't see anything obvious to do this in the OCaml Str l...
I have a string output which is in form of a dict ex. {'key1':'value1','key2':'value2'} how can make easily save it as a dict and not as a string? ...
This is a pretty specific problem, but I'm wondering if anyone would have a brilliant solution. I'm trying to fit a string with a fixed font size in a box of arbitrary size, such that, if the whole string doesn't fit, I want to trim it and ad an ellipses (...). So if my text is "the netherlands" I want to determine what portion of th...
I'm working with a low-level API that accepts a char* and numeric value to represent a string and its length, respectively. My code uses std::basic_string and calls into these methods with the appropriate translation. Unfortunately, many of these methods accept string lengths of varying size (i.e. max(unsigned char), max(short), etc......
Is there an easy way to remove the first 2 and last 2 chars in a string? I have this string: \nTESTSTRING\n How could I easily delete them? ...
In recent bash versions, I can do this: $ string="Universe.World.Country.State.City.Street" $ echo $string Universe.World.Country.State.City.Street $ newString="${string##*.}" $ echo $newString Street Using Python, what is a succinct way to doing the same? I am interested in the last substring after the last period. Thank you! ...
Hi I have text editor widget in smalltalk (visual works) that returns a text object, however I want the text returned to be handled as a string object. How do you parse a text object as a string? ...
I have a string of source code HTML. So I would go: int X = find indexof("theterm"); thesourcecode = thesourcecode.Substring(???? How can I delete all chars from the point where theterm is found BEHIND? Thanks SO. Edit: An example so people dont' get confused. Sample string: "The big red house is so enormous!" int Position = sampl...
My last return statement does not work can anyone tell me why? I am completly lost! public class IpAddress { private String dottedDecimal; private int[] Octet= new int[4]; public int i; //Default constructor public IpAddress() { dottedDecimal = "0.0.0.0"; for ( i=0; i<=3;i++) { Octet[i] = 0; //setting the array to zero ...
I'm trying to reverse an input string var oneway = $('#inputfield').val(); var backway = oneway.reverse(); but firebug is telling me that oneway.reverse() is not a function. Any ideas? Thank you ...
Apparently Java's Regex flavor counts Umlauts and other special characters as non-"word characters" when I use Regex. "TESTÜTEST".replaceAll( "\\W", "" ) returns "TESTTEST" for me. What I want is for only all truly non-"word characters" to be removed. Any way to do this without having something along the lines of "[^...
Test string: the%20matrix%20 How can I delete the last three chars? Using this code gives me an out of index exception: y = y.Substring(y.Length - 4, y.Length - 1); ...
I'm working on an application that needs to accept posted data from a form and process it. One step of this process is to unescape the data that comes in. One issue that I'm facing is that the data I'm grabbing from the form is binary in nature so it includes escape sequences that I need to turn back into characters. This is fairly trivi...
Hi, I am trying to truncate some long text in C#, but I don't want my string to be cut off part way through a word. Does anyone have a function that I can use to truncate my string at the end of a word? E.g: "This was a long string..." Not: "This was a long st..." Thanks, Tim ...
I am trying to write code to reverse a string in place (I'm just trying to get better at C programming and pointer manipulation), but I cannot figure out why I am getting a segmentation fault: int main() { char* s = "teststring"; reverse(s); return 0; } reverse(char* s) { int i,j; char temp; for (i=0,j=(strlen...
Hi I am sorry if this question is too simple but I can't seem to reason this out. I want to parse a string. I want to extract the words between 'The final score is: ' and '.'. In other words, if i have a string "The final score is: 25." I want it to extract 25. I don't know how to do this. Should I use match? or split?? Thanks ...
How do I define a minimum and maximum (possibly unbounded) number of times a certain pattern should repeat itself? I know there's ? and *, with which I could build the pattern by repeating it a certain amount of times, but I know there's a special notation for it using {}, I just can't remember how it is. ...
I want a python script to print list of all functions defined in a C/C++ file. e.g. abc.c defines two functions as: void func1() { } int func2(int i) { printf("%d", i); return 1; } I just want to search the file (abc.c) and print all the functions defined in it (function names only). In the example above, I would like to print func1,...