Search Results

Search found 37934 results on 1518 pages for 'string split'.

Page 11/1518 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • handle null values for string when implementing IXmlSerializable interface

    - by user208081
    I have the following class that implements IXmlSerializable. When implementing WriteXml(), I need to handle the case where the string members of this class may be null values. What is the best way of handling this? Currently, I am using the default constructor in which all the string properties are initialized to empty string values. This way, when WriteXml() is called, the string will not be null. One other way I could do this is check using String.IsNullOrEmpty before writing each string in xml. Any suggestions on how I can improve this code? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Serialization; using System.Globalization; namespace TCS.Common.InformationObjects { public sealed class FaxSender : IXmlSerializable { #region Public Constants private const string DEFAULT_CLASS_NAME = "FaxSender"; #endregion Public Constants #region Public Properties public string Name { get; set; } public string Organization { get; set; } public string PhoneNumber { get; set; } public string FaxNumber { get; set; } public string EmailAddress { get; set; } #endregion Public Properties #region Public Methods #region Constructors public FaxSender() { Name = String.Empty; Organization = String.Empty; PhoneNumber = String.Empty; FaxNumber = String.Empty; EmailAddress = String.Empty; } public FaxSender(string name, string organization, string phoneNumber, string faxNumber, string emailAddress) { Name = name; Organization = organization; PhoneNumber = phoneNumber; FaxNumber = faxNumber; EmailAddress = emailAddress; } #endregion Constructors #region IXmlSerializable Members public System.Xml.Schema.XmlSchema GetSchema() { throw new NotImplementedException(); } public void ReadXml(System.Xml.XmlReader reader) { throw new NotImplementedException(); } public void WriteXml(System.Xml.XmlWriter xmlWriter) { try { // <sender> xmlWriter.WriteStartElement("sender"); // Write the name of the sender as an element. xmlWriter.WriteElementString("name", this.Name.ToString(CultureInfo.CurrentCulture)); // Write the organization of the sender as an element. xmlWriter.WriteElementString("organization", this.Organization.ToString(CultureInfo.CurrentCulture)); // Write the phone number of the sender as an element. xmlWriter.WriteElementString("phone_number", this.PhoneNumber.ToString(CultureInfo.CurrentCulture)); // Write the fax number of the sender as an element. xmlWriter.WriteElementString("fax_number", this.FaxNumber.ToString(CultureInfo.CurrentCulture)); // Write the email address of the sender as an element. xmlWriter.WriteElementString("email_address", this.EmailAddress.ToString(CultureInfo.CurrentCulture)); // </sender> xmlWriter.WriteEndElement(); } catch { // Rethrow any exceptions. throw; } } #endregion IXmlSerializable Members #endregion Public Methods } }

    Read the article

  • Help with split

    - by Andeeh
    I have something that splits each line of a file. here is a sample of a line it might split "James","Project5","15/05/2010","3" I have this code Private Sub Command1_Click() Open jobs For Input As #1 Do While Not EOF(1) Line Input #1, tmpstring splititems = Split(tmpstring, ",") Form1.Print splititems(0) Form1.Print splititems(1); Form1.Print splititems(2); Form1.Print splititems(3) Loop Close #1 End Sub I would like it to instead of outputting a name each time there is a name, just put the project under the name that is already there. e.g. if there was another line in the file with the name james and he had been working on project 2 in that line I would like it to just put project 2 under the "James" that had already been put on the form. Any help would be fantastic

    Read the article

  • FileReader vs FileInputReader. split vs Pattern

    - by abdeslam
    I'm working with a file with about 2G. I want to read the file line by line to find some specific terms. Whitch class can I better use: FileReader or FileInputStream? And how can I find the specific words efficiently. I'm just using the split() method, but may be can I use the java.util.regex.Pattern class in combination with java.util.regex.Matcher class. So the Questions are: which class can I use: the FileReader or the FileInputStream? can I use the split method or the regex classes Does someone has an answer to this questions? Thans.

    Read the article

  • javascript - Google Chrome cluttering Array generated from .split()

    - by patrick
    Given the following string: var str = "one,two,three"; If I split the string on the commas, I normally get an array, as expected: var arr = str.split(/\s*,\s*/); Trouble is that in Google Chrome (for Mac), it appends extra properties to the array. Output from Chrome's debugger: arr: Array 0: one 1: two 2: three constructor: function Array() index: undefined input: undefined length: 3 So if I iterate over the array with a for/in loop, it iterates over the new properties. Specifically the input and index properties. Using hasOwnProperty doesn't seem to help. A fix would be to do a for loop based on the length of the Array. Still I'm wondering if anyone has insight into why Chrome behaves this way. Firefox and Safari don't have this issue.

    Read the article

  • Determining Whether a String Is Contained Within a String Array (Case Insensitive)

    About once every couple of months I need to write a bit of code that does one thing if a particular string is found within an array of strings and something else if it is not ignoring differences in case. For whatever reason, I never seem to remember the code snippet to accomplish this, so after spending 10 minutes of research today I thought I'd write it down here in an effort to help commit it to memory or, at the very least, serve as a quick place to find the answer when the need arises again.So without further adieu, here it is:Visual Basic Version:If stringArrayName.Contains("valueToLookFor", StringComparer.OrdinalIgnoreCase) Then ... Else ... End IfC# Version:if (stringArrayName.Contains("valueToLookFor", StringComparer.OrdinalIgnoreCase)) ... else ...Without the StringComparer.OrdinalIgnoreCase the search will be case-sensitive. For more information on comparing strings, see: New Recommendations for Using Strings in Microsoft .NET 2.0.Happy Programming!Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.

    Read the article

  • How Do I Remove The First 4 Characters From A String If It Matches A Pattern In Ruby

    - by James
    I have the following string: "h3. My Title Goes Here" I basically want to remove the first 4 characters from the string so that I just get back: "My Title Goes Here". The thing is I am iterating over an array of strings and not all have the h3. part in front so I can't just ditch the first 4 characters blindly. I have checked the docs and the closest think I could find was chomp, but that only works for the end of a string. Right now I am doing this: "h3. My Title Goes Here".reverse.chomp(" .3h").reverse This gives me my desired output, but there has to be a better way right? I mean I don't want to reverse a string twice for no reason. I am new to programming so I might have missed something obvious, but I didn't see the opposite of chomp anywhere in the docs. Is there another method that will work? Thanks!

    Read the article

  • Split a Large File In C++

    - by wdow88
    Hey all, I'm trying to write a program that takes a large file (of any time) and splits it into many smaller "chunks". I think I have the basic idea down, but for some reason I cannot create a chunk size over 12,000 bites. I know there are a few solutions on google, etc. but I am more interested in learning what the origin of this limitation is then actually using the program to split files. //This file splits are larger into smaller files of a user inputted size. #include<iostream> #include<fstream> #include<string> #include<sstream> #include <direct.h> #include <stdlib.h> using namespace std; void GetCurrentPath(char* buffer) { _getcwd(buffer, _MAX_PATH); } int main() { // use the function to get the path char CurrentPath[_MAX_PATH]; GetCurrentPath(CurrentPath);//Get the current directory (used for displaying output) fstream bigFile; string filename; int partsize; cout << "Enter a file name: "; cin >> filename; //Recieve target file cout << "Enter the number of bites in each smaller file: "; cin >> partsize; //Recieve volume size bigFile.open(filename.c_str(),ios::in | ios::binary); bigFile.seekg(0, ios::end); // position get-ptr 0 bytes from end int size = bigFile.tellg(); // get-ptr position is now same as file size bigFile.seekg(0, ios::beg); // position get-ptr 0 bytes from beginning for (int i = 0; i <= (size / partsize); i++) { //Build File Name string partname = filename; //The original filename string charnum; //archive number stringstream out; //stringstream object out, used to build the archive name out << "." << i; charnum = out.str(); partname.append(charnum); //put the part name together //Write new file part fstream filePart; filePart.open(partname.c_str(),ios::out | ios::binary); //Open new file with the name built above //Check if near the end of file if (bigFile.tellg() < (size - (size%partsize))) { filePart.write(reinterpret_cast<char *>(&bigFile),partsize); //Write the selected amount to the file filePart.close(); //close file bigFile.seekg(partsize, ios::cur); //move pointer to next position to be written } //Changes the size of the last volume because it is the end of the file else { filePart.write(reinterpret_cast<char *>(&bigFile),(size%partsize)); //Write the selected amount to the file filePart.close(); //close file } cout << "File " << CurrentPath << partname << " produced" << endl; //display the progress of the split } bigFile.close(); cout << "Split Complete." << endl; return 0; } Any ideas? Thanks!

    Read the article

  • Using perl to split a line that may contain whitespace

    - by Tommy Fisk
    Okay, so I'm using perl to read in a file that contains some general configuration data. This data is organized into headers based on what they mean. An example follows: [vars] # This is how we define a variable! $var = 10; $str = "Hello thar!"; # This section contains flags which can be used to modify module behavior # All modules read this file and if they understand any of the flags, use them [flags] Verbose = true; # Notice the errant whitespace! [path] WinPath = default; # Keyword which loads the standard PATH as defined by the operating system. Append with additonal values. LinuxPath = default; Goal: Using the first line as an example "$var = 10;", I'd like to use the split function in perl to create an array that contains the characters "$var" and "10" as elements. Using another line as an example: Verbose = true; # Should become [Verbose, true] aka no whitespace is present This is needed because I will be outputting these values to a new file (which a different piece of C++ code will read) to instantiate dictionary objects. Just to give you a little taste of what it might look like (just making it up as I go along): define new dictionary name: [flags] # Start defining keys => values new key name: Verbose new value val: 10 # End dictionary Oh, and here is the code I currently have along with what it is doing (incorrectly): sub makeref($) { my @line = (split (/=/)); # Produces ["Verbose", " true"]; }

    Read the article

  • Java splitting string by custom regex match

    - by slikz
    I am completely new to regular expressions so I'm looking for a bit of help here. I am compiling under JDK 1.5 Take this line as an example that I read from standard input: ab:Some string po:bubblegum What I would like to do is split by the two characters and colon. That is, once the line is split and put into a string array, these should be the terms: ab:Some string po:bubblegum I have this regex right now: String[] split = input.split("[..:]"); This splits at the semicolon; what I would like is for it to match two characters and a semicolon, but split at the space before that starts. Is this even possible? Here is the output from the string array: ab Some String po bubblegum I've read about Pattern.compile() as well. Is this something I should be considering?

    Read the article

  • Splitting a string which contain multiple symbols to get specific values

    - by Eon Rusted du Plessis
    I cannot believe I am having trouble with this following string String filter = "name=Default;pattern=%%;start=Last;end=Now"; This is a short and possibly duplicate question, but how would I split this string to get: string Name = "Default"; string Pattern = "%%" ; string start = "Last" ; string end = "Now" ; Reason why I ask is my deadline is very soon, and this is literally the last thing I must do. I'm Panicking, and I'm stuck on this basic command. I tried: pattern = filter.Split(new string[] { "pattern=", ";" }, StringSplitOptions.RemoveEmptyEntries)[1]; //Gets the pattern startDate = filter.Split(new string[] { "start=", ";" }, StringSplitOptions.RemoveEmptyEntries)[1]; //Gets the start date I happen to get the pattern which I needed, but as soon as I try to split start, I get the value as "Pattern=%%" What can I do? Forgot to mention The list in this string which needs splitting may not be in any particular order . this is a single sample of a string which will be read out of a stringCollection (reading these filters from Properties.Settings.Filters

    Read the article

  • Python slicing a string using space characters and a maximum length

    - by chrism
    I'd like to slice a string up in a similar way to .split() (so resulting in a list) but in a more intelligent way: I'd like it to split it into chunks that are up to 15 characters, but are not split mid word so: string = 'A string with words' [splitting process takes place] list = ('A string with','words') The string in this example is split between 'with' and 'words' because that's the last place you can split it and the first bit be 15 characters or less.

    Read the article

  • Building a regexp to split a string

    - by Kivin
    I'm seeking a solution to splitting a string which contains text in the following format: "abcd efgh 'ijklm no pqrs' tuv" which will produce the following results: ['abcd', 'efgh', 'ijklm no pqrs', 'tuv'] In otherwords, it splits by whitespace unless inside of a single quoted string. I think it could be done with .NET regexps using "Lookaround" operators, particularly balancing operators. I'm not so sure about perl.

    Read the article

  • How to use Split with jQuery?

    - by Matt
    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 yet.

    Read the article

  • Best way to split a string by word (SQL Batch separator)

    - by Paul Kohler
    I have a class I use to "split" a string of SQL commands by a batch separator - e.g. "GO" - into a list of SQL commands that are run in turn etc. ... private static IEnumerable<string> SplitByBatchIndecator(string script, string batchIndicator) { string pattern = string.Concat("^\\s*", batchIndicator, "\\s*$"); RegexOptions options = RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Multiline; foreach (string batch in Regex.Split(script, pattern, options)) { yield return batch.Trim(); } } My current implementation uses a Regex with yield but I am not sure if it's the "best" way. It should be quick It should handle large strings (I have some scripts that are 10mb in size for example) The hardest part (that the above code currently does not do) is to take quoted text into account Currently the following SQL will incorrectly get split: var batch = QueryBatch.Parse(@"-- issue... insert into table (name, desc) values('foo', 'if the go is on a line by itself we have a problem...')"); Assert.That(batch.Queries.Count, Is.EqualTo(1), "This fails for now..."); I have thought about a token based parser that tracks the state of the open closed quotes but am not sure if Regex will do it. Any ideas!?

    Read the article

  • Regex split into overlapping strings

    - by polygenelubricants
    I'm exploring the power of regular expressions, so I'm just wondering if something like this is possible: public class StringSplit { public static void main(String args[]) { System.out.println( java.util.Arrays.deepToString( "12345".split(INSERT_REGEX_HERE) ) ); // prints "[12, 23, 34, 45]" } } If possible, then simply provide the regex (and preemptively some explanation on how it works). If it's only possible in some regex flavors other than Java, then feel free to provide those as well. If it's not possible, then please explain why.

    Read the article

  • PHP String Split

    - by deniz
    I need to split a string into chunks of 2,2,3,3 characters and was able to do so in Perl by using unpack: unpack("A2A2A3A3", 'thisisloremipsum'); However the same function does not work in PHP, it gives this output: Array ( [A2A3A3] => th ) How can I do this by using unpack? I don't want to write a function for it, it should be possible with unpack but how? Thanks in advance,

    Read the article

  • javascript number split

    - by Jaron787
    Can anyboyd help me split up this date number in javascript so that when it is outputted to the screen it has slashes between the 4th and 5th number and the 6th and 7th number, so that it can be understood by a vxml voice browser. The number can be any value so i need it to work for any eight digit number. Like so: 20100820 2010/08/20 Many thanks

    Read the article

  • mysql split value from one field to two

    - by tsiger
    Hello, I 've got a table field (membername) which contains both the last name and the first name of users. Is it possible to split those into 2 fields (memberfirst - memberlast)? All the records have this format "Firstname Lastname" (without quotes and a space in between).

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >