Rectangle 27 1

Well, grep is a separate program (which you could also use). In Emacs, you'd use the function search-forward-regexp, which you can run using either M-x (hold Meta, usually Alt key, and press x) and then type search-forward-regexp and press Return.

You'll then need to key in the regexp to search. Put simply, it seems like you want to ignore |< something >, which in Emacs's variety of regexes is:

|<[a-z]+>
a|<[a-z]+> comedy|<[a-z]+> show|<[a-z]+>

You can create a Lisp function to convert a string this way, by splitting it on spaces and adding the regex sequences:

(defun find-string-in-funny-file (s)                        ; Define a function
  "Find a string in the file with the |<foo> things in it." ; Document its purpose
  (interactive "sString to find: ")                         ; Accept input if invoked interactively with M-x
  (push-mark)                                               ; Save the current location, so `pop-global-mark' can return here
                                                            ; (usually C-u C-SPC)
  (goto-char 0)                                             ; Start at the top of the file
  (let ((re (apply #'concat                                 ; join into one string
                   (cl-loop 
                    for word in (split-string s " ")        ; for each word in `s'
                    collect (regexp-quote word)             ; collect that word, plus
                    collect "|<[a-z]+> "))))                ; also the regex bits to skip
    (search-forward-regexp                                  ; search for the next occurrence
     (substring re 0 (- (length re) 2)))))                  ; after removing the final space from `re'

You can explore what those functions each do in the (online) Emacs Lisp manual; for example, pick from the menu "HelpDescribeFunction" or press C-h f (Control+h, then f) and type interactive (RET) for the manual's documentation of that special form.

If you paste the above (defun) into the *scratch* buffer, and position the cursor after the final ) at the end, you can press C-j to evaluate it, and the function will remain with you until you close Emacs.

If you save it in a file named something .el, you can use M-x load-file to load it again in future.

If you then load your "funny" file, and type M-x find-string-in-funny-file, it'll search your file for your string, and leave the cursor on the string. If it's not found, you'll see a message to that effect.

BUGS: The function is less than spectacular style

You can process the words with regexp-quote to protect against unintentional use of regexp-special characters.

Thanks, I knew it existed. I'll patch the above.

elisp - The lisp that convert string and grep in emacs? - Stack Overfl...

emacs elisp find-grep
Rectangle 27 1

A simpler solution to parse your string would be to use the function REGEXP to find the indices where you have 2 or more whitespace characters in a row, use these indices to break your string up into a cell array of strings using the function MAT2CELL, then use the function STRTRIM to remove leading and trailing whitespace from each substring. For example:

>> str = 'DATE      TIMESTAMP    T W M     T AL M C  A_B_C';
>> cutPoints = regexp(str,'\s{2,}');
>> cellArr = mat2cell(str,1,diff([0 cutPoints numel(str)]));
>> cellArr = strtrim(cellArr)

cellArr = 

    'DATE'    'TIMESTAMP'    'T W M'    'T AL M C'    'A_B_C'

file io - Matlab: How can I read in a string separated with spaces but...

matlab file-io textscan
Rectangle 27 19

This is all implementation defined. I'm using VC10 Beta2. The key to help understanding this stuff (the implementation of virtual functions), you need to know about a secret switch in the Visual Studio compiler, /d1reportSingleClassLayoutXXX. I'll get to that in a second.

Does it mean that only one vptr is there even both of class B and class A have virtual function? Why there is only one vptr?

This is how virtual functions work, you want the base class and derived class to share the same vtable pointer (pointing to the implementation in the derived class.

It seems that in this case, two vptrs are in the layout.....How does this happen? I think the two vptrs one is for class A and another is for class B....so there is no vptr for the virtual function of class C?

This is the layout of class C, as reported by /d1reportSingleClassLayoutC:

class C size(20):
        +---
        | +--- (base class A)
 0      | | {vfptr}
 4      | | a
        | +---
        | +--- (base class B)
 8      | | {vfptr}
12      | | b
        | +---
16      | c
        +---

You are correct, there are two vtables, one for each base class. This is how it works in multiple inheritance; if the C* is casted to a B*, the pointer value gets adjusted by 8 bytes. A vtable still needs to be at offset 0 for virtual function calls to work.

The vtable in the above layout for class A is treated as class C's vtable (when called through a C*).

The sizeof B is 16 bytes -------------- Without virtual it should be 4 + 4 + 4 = 12. why there is another 4 bytes here? What's the layout of class B ?

This is the layout of class B in this example:

class B size(20):
        +---
 0      | {vfptr}
 4      | {vbptr}
 8      | b
        +---
        +--- (virtual base A)
12      | {vfptr}
16      | a
        +---

As you can see, there is an extra pointer to handle virtual inheritance. Virtual inheritance is complicated.

The sizeof D is 32 bytes -------------- it should be 16(class B) + 12(class C) + 4(int d) = 32. Is that right?

No, 36 bytes. Same deal with the virtual inheritance. Layout of D in this example:

class D size(36):
        +---
        | +--- (base class B)
 0      | | {vfptr}
 4      | | {vbptr}
 8      | | b
        | +---
        | +--- (base class C)
        | | +--- (base class A)
12      | | | {vfptr}
16      | | | a
        | | +---
20      | | c
        | +---
24      | d
        +---
        +--- (virtual base A)
28      | {vfptr}
32      | a
        +---

My question is , why there is an extra space when virtual inheritance is applied?

Virtual base class pointer, it's complicated. Base classes are "combined" in virtual inheritance. Instead of having a base class embedded into a class, the class will have a pointer to the base class object in the layout. If you have two base classes using virtual inheritance (the "diamond" class hierarchy), they will both point to the same virtual base class in the object, instead of having a separate copy of that base class.

What's the underneath rule for the object size in this case?

Important point; there are no rules: the compiler can do whatever it needs to do.

cl test.cpp /d1reportSingleClassLayoutXXX

Where XXX is a substring match of the structs/classes you want to see the layout of. Using this you can explore the affects of various inheritance schemes yourself, as well as why/where padding is added, etc.

I would like to point out that while this is a really excellent answer, these details are specific to a particular implementation. Implementations are allowed to differ wildly from this as long as they make the feature work. There are no rules or guarantees about how the memory of a class is layed out. This answer does represent a set of implementation techniques that are very similar on several different compilers and on several different platforms, but there can be and are major differences for some compilers on some platforms.

While writing objects to a file, I directly write the entire object to file using write(). So virtual adds 4 more bytes (or 8 more bytes depending on the architecture) while writing. Is there any way we can avoid this?

c++ - object size with virtual - Stack Overflow

c++
Rectangle 27 5

I have also created a function to convert a CSV to a usable format for Bulk Insert. I used the answered post by Chris Clark as a starting point to create the following C# function.

I ended up using a regular expression to find the fields. I then recreated the file line by line, writing it to a new file as I went, thus avoiding having the entire file loaded into memory.

private void CsvToOtherDelimiter(string CSVFile, System.Data.Linq.Mapping.MetaTable tbl)
{
    char PH1 = '|';
    StringBuilder ln;

    //Confirm file exists. Else, throw exception
    if (File.Exists(CSVFile))
    {
        using (TextReader tr = new StreamReader(CSVFile))
        {
            //Use a temp file to store our conversion
            using (TextWriter tw = new StreamWriter(CSVFile + ".tmp"))
            {
                string line = tr.ReadLine();
                //If we have already converted, no need to reconvert.
                //NOTE: We make the assumption here that the input header file 
                //      doesn't have a PH1 value unless it's already been converted.
                if (line.IndexOf(PH1) >= 0)
                {
                    tw.Close();
                    tr.Close();
                    File.Delete(CSVFile + ".tmp");
                    return;
                }
                //Loop through input file
                while (!string.IsNullOrEmpty(line))
                {
                    ln = new StringBuilder();

                    //1. Use Regex expression to find comma separated values 
                    //using quotes as optional text qualifiers 
                    //(what MS EXCEL does when you import a csv file)
                    //2. Remove text qualifier quotes from data
                    //3. Replace any values of PH1 found in column data 
                    //with an equivalent character
                    //Regex:  \A[^,]*(?=,)|(?:[^",]*"[^"]*"[^",]*)+|[^",]*"[^"]*\Z|(?<=,)[^,]*(?=,)|(?<=,)[^,]*\Z|\A[^,]*\Z
                    List<string> fieldList = Regex.Matches(line, @"\A[^,]*(?=,)|(?:[^"",]*""[^""]*""[^"",]*)+|[^"",]*""[^""]*\Z|(?<=,)[^,]*(?=,)|(?<=,)[^,]*\Z|\A[^,]*\Z")
                            .Cast<Match>()
                            .Select(m => RemoveCSVQuotes(m.Value).Replace(PH1, ''))
                            .ToList<string>();

                    //Add the list of fields to ln, separated by PH1
                    fieldList.ToList().ForEach(m => ln.Append(m + PH1));

                    //Write to file. Don't include trailing PH1 value.
                    tw.WriteLine(ln.ToString().Substring(0, ln.ToString().LastIndexOf(PH1)));

                    line = tr.ReadLine();
                }


                tw.Close();
            }
            tr.Close();

            //Optional:  replace input file with output file
            File.Delete(CSVFile);
            File.Move(CSVFile + ".tmp", CSVFile);
        }
    }
    else
    {
        throw new ArgumentException(string.Format("Source file {0} not found", CSVFile));
    }
}
//The output file no longer needs quotes as a text qualifier, so remove them
private string RemoveCSVQuotes(string value)
{
    //if is empty string, then remove double quotes
    if (value == @"""""") value = "";
    //remove any double quotes, then any quotes on ends
    value = value.Replace(@"""""", @"""");
    if (value.Length >= 2)
        if (value.Substring(0, 1) == @"""")
            value = value.Substring(1, value.Length - 2);
    return value;
}

works great but replaces files and doesn't account for accented characters so make sure to include the encoding in the streamreader. Other than that. Thanks!=]

SQL Server Bulk insert of CSV file with inconsistent quotes - Stack Ov...

sql-server csv bulkinsert
Rectangle 27 0

Assuming a Sharepoint WebPart uses XslCompiledTransform and allows you to use XSLT with embedded C# or VB.NET code to implement an extension function the following should help:

<xsl:stylesheet 
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    exclude-result-prefixes="msxsl mf content"
    xmlns:mf="http://example.com/mf"
>
  <msxsl:script implements-prefix="mf" language="C#">
    <msxsl:using namespace="System.IO"/>
  public XPathNavigator ParseFragment(string markupFragment)
  {
    using (StringReader sr = new StringReader(markupFragment))
    {
      using (XmlReader xr = XmlReader.Create(sr, 
        new XmlReaderSettings() { ConformanceLevel = ConformanceLevel.Fragment }))
      {
        XPathDocument doc = new XPathDocument(xr);
        return doc.CreateNavigator();
      }
    }
  }
  </msxsl:script>


  <xsl:output method="html"/>

  <xsl:template match="content:encoded">
    <xsl:apply-templates select="mf:ParseFragment(.)/span/img"/>
  </xsl:template>

  <xsl:template match="img">
    <img alt="" src="{@src}" width="75" height="49" />
  </xsl:template>
</xsl:stylesheet>

Note however that applying an XML parser on the markup in the CDATA section requires it conforms to the XML syntax rules so parsing X(HT)ML stuff like

<content:encoded>
    <![CDATA[
        <span><img width="200" src="foo.png"/></span><br /> [some Text] ]]>
  </content:encoded>
<content:encoded>
    <![CDATA[
        <span><img width="200" src="foo.png"></span><br> [some Text] ]]>
  </content:encoded>

will not work. Unfortunately the .NET framework class library does not come with an HTML parsing API so if the content of the content:encoded element is HTML you would need to look for a third party HTML parser like HTMLAgilityPack to perform the job XPathDocument does in my sample or you are really left with XPath 1.0's poor string parsing support:

<xsl:stylesheet 
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl content"
>

  <xsl:template match="content:encoded">
    <img alt="" src="{substring-before(substring-after(., 'src=&quot;'), '&quot;')}" width="75" height="49"/>
  </xsl:template>
</xsl:stylesheet>

image - Get -SRC out of (xsl - RSS Viewer WP) -...

image xslt rss cdata
Rectangle 27 0

/* 1. Transform your string into lower case
2. Split your string into an array. Notice the white space i'm using for separator
3. Iterate the new array, and assign the current iteration value (array[c]) a new formatted string:
 - With the sentence: array[c][0].toUpperCase() the first letter of the string converts to upper case.
 - With the sentence: array[c].substring(1) we get the rest of the string (from the second letter index to the last one).
 - The "add" (+) character is for concatenate both strings. 
4. return array.join(' ') // returns the formatted array like a new string.*/


function titleCase(str){
    str = str.toLowerCase();
    var array = str.split(' ');
    for(var c = 0; c < array.length; c++){
        array[c] = array[c][0].toUpperCase() + array[c].substring(1);
    }
return array.join(' ');
}

titleCase("I'm a little tea pot");

Capitalize First Letter of each word in a String - JavaScript - Stack ...

javascript string capitalize charat