EzDevInfo.com

split interview questions

Top split frequently asked interview questions

Swift: Split a String into an array

Say I have a string here:

var fullName: String = "First Last"

I want to split the string base on white space and assign the values to their respective variables

var fullNameArr = // something like: fullName.explode(" ") 

var firstName: String = fullNameArr[0]
var lastName: String? = fullnameArr[1]

Also, sometimes users might not have a last name.


Source: (StackOverflow)

How can I split up a Git commit buried in history?

I flubbed up my history and want to do some changes to it. Problem is, I have a commit with two unrelated changes, and this commit is surrounded by some other changes in my local (non-pushed) history.

I want to split up this commit before I push it out, but most of the guides I'm seeing have to do with splitting up your most recent commit, or uncommitted local changes. Is it feasible to do this to a commit that is buried in history a bit, without having to "re-do" my commits since then?


Source: (StackOverflow)

Advertisements

C# Split A String By Another String

I've been using the Split() method to split strings, but this only appears to work if you are splitting a string by a character. Is there any way to split a string, with another string being the split by parameter? I've tried converting the splitter into a character array, with no luck.

In other words, I'd like to split the string:

THExxQUICKxxBROWNxxFOX

by xx, and return an array with values:

THE, QUICK, BROWN, FOX


Source: (StackOverflow)

Convert comma separated string to array

I have a comma separated string that I want to convert into an array so I can loop through it.

Is there anything built-in to do this?

For e.g. I have this string

var str = "January,February,March,April,May,June,July,August,September,October,November,December";

now want to split this by comma and store in Array object


Source: (StackOverflow)

Split string into an array in Bash

In a Bash script I would like to split a line into pieces and put them into an array.

The line:

Paris, France, Europe

I would like to have them in an array like this:

array[0] = Paris
array[1] = France
array[2] = Europe

I would like to use simple code, the command's speed doesn't matter. How can I do it?


Source: (StackOverflow)

How do I split a string, breaking at a particular character?

I have this string

'john smith~123 Street~Apt 4~New York~NY~12345'

Using JavaScript, what is the fastest way to parse this into

var name = "john smith";
var street= "123 Street";
//etc...

Source: (StackOverflow)

How do I split a string with multiple separators in javascript?

How do I split a string with multiple separators in JavaScript? I'm trying to split on both commas and spaces but, AFAIK, JS's split function only supports one separator.


Source: (StackOverflow)

Split string into a list in Python

I want my python function to split a sentence (input) and store each word in a list. The code that I've written so far splits the sentence, but does not store the words as a list. How do I do that?

def split_line(text):

    # split the text
    words = text.split()

    # for each word in the line:
    for word in words:

        # print the word
        print(words)

Source: (StackOverflow)

Split Java String by New Line

I'm trying to split text in a JTextArea using a regex to split the String by \n However, this does not work and I also tried by \r\n|\r|n and many other combination of regexes. Code:

public void insertUpdate(DocumentEvent e) {
    String split[], docStr = null;
    Document textAreaDoc = (Document)e.getDocument();

    try {
        docStr = textAreaDoc.getText(textAreaDoc.getStartPosition().getOffset(), textAreaDoc.getEndPosition().getOffset());
    } catch (BadLocationException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    split = docStr.split("\\n");
}

Source: (StackOverflow)

How do I tokenize a string in C++?

Java has a convenient split method:

String str = "The quick brown fox";
String[] results = str.split(" ");

Is there an easy way to do this in C++?


Source: (StackOverflow)

Cancel split window in Vim

I have split my windows horizontally. Now how can I return to normal mode, i.e. no split window just one window without cancelling all of my open windows. I have 5 and do not want to "quit", just want to get out of split window.


Source: (StackOverflow)

How to Change size of split screen emacs windows?

So I have emacs split horizontally - on top I'm editting Perl code, the bottom is the shell. By default emacs makes the two windows equal in size, but I'd like the shell buffer smaller (maybe half the size?). I was wondering how I could do that.

Thank you!


Source: (StackOverflow)

A method to reverse effect of java String.split()?

I am looking for a method to combine an array of strings into a delimited String. An opposite to split(). I've seen this in other languages.

Wanted to ask the forum before I try writing my own( since the JDK has everything...)

Thanks,


Source: (StackOverflow)

How to use split?

I need to break apart a string that always looks like this:

something -- something_else.

I need to put "something_else" in another input field. Currently, this string example is being added to an HTML table row on the fly like this:

tRow.append($('<td>').text($('[id$=txtEntry2]').val()));

I figure "split" is the way to go, but there is very little documentation that I can find.


Source: (StackOverflow)

Scanner vs. StringTokenizer vs. String.Split

I just learned about Java's Scanner class and now I'm wondering how it compares/competes with the StringTokenizer and String.Split. I know that the StringTokenizer and String.Split only work on Strings, so why would I want to use the Scanner for a String? Is Scanner just intended to be one-stop-shopping for spliting?


Source: (StackOverflow)