working on it ...

Filters

Explore Public Snippets

Sort by

Found 6,071 snippets matching: input

    public by cghersi  475258  5  7  0

    C#: Parse a comma separated string into a collection of numeric items

    This method can be used with any separator you need, just setting the 'separator' input
    public static List<long> ParseIntoListOfLongs(string content, char separator = ',')
    {
        List<long> ids = new List<long>();
    
        if (string.IsNullOrEmpty(content))
            return ids;
    
        string[] strIds = content.Split(separator);
        foreach (string str in strIds)
        {
            long id = -1;
            if (long.TryParse(str, out id))
            {
                if (id > 0)
                    ids.Add(id);
            }
        }
    
        return ids;
    }
    

    public by johansonkatherine  219731  1  6  2

    C# Code Sample to Replace Multiple Texts inside PDF File Using Cloud API

    The following code sample shows how developers can replace multiple texts in a single API call in a PDF file using Aspose.Pdf for Cloud API in their applications. Developers can use Aspose REST API with any language: .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more.
    AsposeApp.AppSID  = "77***********************************";
    AsposeApp.AppKey = "9a*******************************";
    
    //build URI
    stringstrURI = "http://api.aspose.com/v1.1/pdf/test.pdf/replaceTextList";
    
    //sign URI
    stringsignedURI = Utils.Sign(strURI);
    
    //build JSON to post
    TextReplace textReplace1 = new TextReplace();
    textReplace1.OldValue = "[!firm!]";
    textReplace1.NewValue = "Aspose";
    textReplace1.Regex = "false";
    
    //build JSON to post
    TextReplace textReplace2 = new TextReplace();
    textReplace2.OldValue = "[!client!]";
    textReplace2.NewValue = "Mark";
    textReplace2.Regex = "false";
    
    MultipleTextReplacestextReplaces = new MultipleTextReplaces();
    textReplaces.TextReplaces = new TextReplace[] { textReplace1, textReplace2 };
    stringstrJSON = JsonConvert.SerializeObject(textReplaces);
    Console.Write(strJSON);
    Utils.ProcessCommand(signedURI, "POST", strJSON);
    
    //build URI
    strURI = "http://api.aspose.com/v1.1/storage/file/test.pdf";
    
    //sign URI
    signedURI = Utils.Sign(strURI);
    
    Stream responseStream = Utils.ProcessCommand(signedURI, "GET");
    using (Stream fileStream = System.IO.File.OpenWrite(@"test.pdf"))
    {
    Utils.CopyStream(responseStream, fileStream);
    }
    responseStream.Close();
    
    //Following are required classes
    public class MultipleTextReplaces
        {
    publicTextReplace[] TextReplaces { get; set; }
        }
    public class TextReplace
        {
    publicTextReplace() { }
    
    public string OldValue { get; set; }
    public string NewValue { get; set; }
    public string Regex { get; set; }
    
        }
    

    public by sherazam  228330  0  5  0

    How to Insert Check Boxes or HTML into Word Docs during Mail Merge inside .NET Apps

    How to Insert Check Boxes or HTML into Word Docs during Mail Merge inside .NET Apps
    // Enter here the actual content of the snippet.            
    //[C# Code Sample]
     
    using System;
    using System.IO;
    using System.Reflection;
    using Aspose.Words;
    using Aspose.Words.Fields;
    using Aspose.Words.MailMerging;
    
    namespace MailMergeFormFields
    {
        /// <summary>
        /// This sample shows how to insert check boxes and text input form fields during mail merge into a document.
        /// </summary>
        class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            public static void Main(string[] args)
            {
                Program program = new Program();
                program.Execute();
            }
    
            private void Execute()
            {
                string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar;
                string dataDir = new Uri(new Uri(exeDir), @"../../Data/").LocalPath;
    
                // Load the template document.
                Document doc = new Document(dataDir + "Template.doc");
    
                // Setup mail merge event handler to do the custom work.
                doc.MailMerge.FieldMergingCallback = new HandleMergeField();
    
                // This is the data for mail merge.
                String[] fieldNames = new String[] {"RecipientName", "SenderName", "FaxNumber", "PhoneNumber",
                    "Subject", "Body", "Urgent", "ForReview", "PleaseComment"};
                Object[] fieldValues = new Object[] {"Josh", "Jenny", "123456789", "", "Hello",
                    "<b>HTML Body Test message 1</b>", true, false, true};
    
                // Execute the mail merge.
                doc.MailMerge.Execute(fieldNames, fieldValues);
    
                // Save the finished document.
                doc.Save(dataDir + "Template Out.doc");
            }
    
            private class HandleMergeField : IFieldMergingCallback
            {
                /// <summary>
                /// This handler is called for every mail merge field found in the document,
                ///  for every record found in the data source.
                /// </summary>
                void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
                {
                    if (mBuilder == null)
                        mBuilder = new DocumentBuilder(e.Document);
    
                    // We decided that we want all boolean values to be output as check box form fields.
                    if (e.FieldValue is bool)
                    {
                        // Move the "cursor" to the current merge field.
                        mBuilder.MoveToMergeField(e.FieldName);
    
                        // It is nice to give names to check boxes. Lets generate a name such as MyField21 or so.
                        string checkBoxName = string.Format("{0}{1}", e.FieldName, e.RecordIndex);
    
                        // Insert a check box.
                        mBuilder.InsertCheckBox(checkBoxName, (bool)e.FieldValue, 0);
    
                        // Nothing else to do for this field.
                        return;
                    }
    
                    // We want to insert html during mail merge.
                    if (e.FieldName == "Body")
                    {
                        mBuilder.MoveToMergeField(e.FieldName);
                        mBuilder.InsertHtml((string)e.FieldValue);
                    }
    
                    // Another example, we want the Subject field to come out as text input form field.
                    if (e.FieldName == "Subject")
                    {
                        mBuilder.MoveToMergeField(e.FieldName);
                        string textInputName = string.Format("{0}{1}", e.FieldName, e.RecordIndex);
                        mBuilder.InsertTextInput(textInputName, TextFormFieldType.Regular, "", (string)e.FieldValue, 0);
                    }
                }
    
                void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args)
                {
                    // Do nothing.
                }
    
                private DocumentBuilder mBuilder;
            }
        }
    }
     
    //[VB.NET Code Sample]
     
    
    Imports Microsoft.VisualBasic
    Imports System
    Imports System.IO
    Imports System.Reflection
    Imports Aspose.Words
    Imports Aspose.Words.Fields
    Imports Aspose.Words.MailMerging
    
    Namespace MailMergeFormFields
        ''' <summary>
        ''' This sample shows how to insert check boxes and text input form fields during mail merge into a document.
        ''' </summary>
        Friend Class Program
            ''' <summary>
            ''' The main entry point for the application.
            ''' </summary>
            Public Shared Sub Main(ByVal args() As String)
                Dim program As New Program()
                program.Execute()
            End Sub
    
            Private Sub Execute()
                Dim exeDir As String = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar
                Dim dataDir As String = New Uri(New Uri(exeDir), "../../Data/").LocalPath
    
                ' Load the template document.
                Dim doc As New Document(dataDir & "Template.doc")
    
                ' Setup mail merge event handler to do the custom work.
                doc.MailMerge.FieldMergingCallback = New HandleMergeField()
    
                ' This is the data for mail merge.
                Dim fieldNames() As String = {"RecipientName", "SenderName", "FaxNumber", "PhoneNumber", "Subject", "Body", "Urgent", "ForReview", "PleaseComment"}
                Dim fieldValues() As Object = {"Josh", "Jenny", "123456789", "", "Hello", "<b>HTML Body Test message 1</b>", True, False, True}
    
                ' Execute the mail merge.
                doc.MailMerge.Execute(fieldNames, fieldValues)
    
                ' Save the finished document.
                doc.Save(dataDir & "Template Out.doc")
            End Sub
    
            Private Class HandleMergeField
                Implements IFieldMergingCallback
                ''' <summary>
                ''' This handler is called for every mail merge field found in the document,
                '''  for every record found in the data source.
                ''' </summary>
                Private Sub IFieldMergingCallback_FieldMerging(ByVal e As FieldMergingArgs) Implements IFieldMergingCallback.FieldMerging
                    If mBuilder Is Nothing Then
                        mBuilder = New DocumentBuilder(e.Document)
                    End If
    
                    ' We decided that we want all boolean values to be output as check box form fields.
                    If TypeOf e.FieldValue Is Boolean Then
                        ' Move the "cursor" to the current merge field.
                        mBuilder.MoveToMergeField(e.FieldName)
    
                        ' It is nice to give names to check boxes. Lets generate a name such as MyField21 or so.
                        Dim checkBoxName As String = String.Format("{0}{1}", e.FieldName, e.RecordIndex)
    
                        ' Insert a check box.
                        mBuilder.InsertCheckBox(checkBoxName, CBool(e.FieldValue), 0)
    
                        ' Nothing else to do for this field.
                        Return
                    End If
    
                    ' We want to insert html during mail merge.
                    If e.FieldName = "Body" Then
                        mBuilder.MoveToMergeField(e.FieldName)
                        mBuilder.InsertHtml(DirectCast(e.FieldValue, String))
                    End If
    
                    ' Another example, we want the Subject field to come out as text input form field.
                    If e.FieldName = "Subject" Then
                        mBuilder.MoveToMergeField(e.FieldName)
                        Dim textInputName As String = String.Format("{0}{1}", e.FieldName, e.RecordIndex)
                        mBuilder.InsertTextInput(textInputName, TextFormFieldType.Regular, "", CStr(e.FieldValue), 0)
                    End If
                End Sub
    
                Private Sub ImageFieldMerging(ByVal args As ImageFieldMergingArgs) Implements IFieldMergingCallback.ImageFieldMerging
                    ' Do nothing.
                End Sub
    
                Private mBuilder As DocumentBuilder
            End Class
        End Class
    End Namespace
    
    

    public by Geometry  1026  0  4  0

    FromSummary: Creates a new <see cref="LogisticRegressionAnalysis"/> from summarized data. In summary data, instead of having a set of inputs and their associated outputs, we have the number of times an input vector had a positi...

    Creates a new from summarized data. In summary data, instead of having a set of inputs and their associated outputs, we have the number of times an input vector had a positive label in the data set and how many times it had a negative label. The input data. The number of positives labels for each input vector. The number of nega
    #endregion
    
    /// <summary>
    ///   Creates a new <see cref="LogisticRegressionAnalysis"/> from summarized data.
    ///   In summary data, instead of having a set of inputs and their associated outputs,
    ///   we have the number of times an input vector had a positive label in the data set
    ///   and how many times it had a negative label.
    /// </summary>
    /// 
    /// <param name="data">The input data.</param>
    /// <param name="positives">The number of positives labels for each input vector.</param>
    /// <param name="negatives">The number of negative labels for each input vector.</param>
    /// 
    /// <returns>
    ///   A <see cref="LogisticRegressionAnalysis"/> created from the given summary data.
    /// </returns>
    /// 
    public static LogisticRegressionAnalysis FromSummary(double[][] data, int[] positives, int[] negatives)
    {
        double[] rate = new double[data.Length];
        double[] weights = new double[data.Length];
    
        for (int i = 0; i < rate.Length; i++)
        {
            rate[i] = positives[i] / (double)(positives[i] + negatives[i]);
            weights[i] = positives[i] + negatives[i];
        }
    
        return new LogisticRegressionAnalysis(data, rate, weights);
    }

    public by arkanoid  18047  1  6  2

    HTML - Removing the outline on an input field

    The annoying blue border outlining the input field in focus can be removed with a simple CSS rule
    input[type=text]:focus{
        outline: 0;
    }
    

    public by Geometry  74880  1  3  0

    CreateGaussianBernoulli: Creates a Gaussian-Bernoulli network.

    Creates a Gaussian-Bernoulli network. The number of inputs for the network. The number of hidden neurons in each layer.
    /// <summary>
    ///   Creates a Gaussian-Bernoulli network.
    /// </summary>
    /// 
    /// <param name="inputsCount">The number of inputs for the network.</param>
    /// <param name="hiddenNeurons">The number of hidden neurons in each layer.</param>
    /// 
    public static DeepBeliefNetwork CreateGaussianBernoulli(int inputsCount, params int[] hiddenNeurons)
    {
        DeepBeliefNetwork network = new DeepBeliefNetwork(inputsCount, hiddenNeurons);
    
        GaussianFunction gaussian = new GaussianFunction();
        foreach (StochasticNeuron neuron in network.machines[0].Visible.Neurons)
            neuron.ActivationFunction = gaussian;
    
        return network;
    }

    public by Geometry  71580  0  5  0

    Normal: Constructs a new Naïve Bayes Classifier.

    Constructs a new Naïve Bayes Classifier. The number of output classes. The number of input variables.
    /// <summary>
    ///   Constructs a new Naïve Bayes Classifier.
    /// </summary>
    /// 
    /// <param name="classes">The number of output classes.</param>
    /// <param name="inputs">The number of input variables.</param>
    /// 
    public static NaiveBayes<NormalDistribution> Normal(int classes, int inputs)
    {
        return Normal(classes, inputs, NormalDistribution.Standard);
    }

    public by Geometry  1220  1  5  0

    Decodes string input

    using System;
    using System.Linq;
    using System.Text;
    using CoiniumServ.Coin.Address.Exceptions;
    using CoiniumServ.Cryptology;
    using Org.BouncyCastle.Math;
    
    private const string Alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
    
    /// <exception cref="AddressFormatException"/>
    public static byte[] Decode(string input)
    {
        var bytes = DecodeToBigInteger(input).ToByteArray();
        // We may have got one more byte than we wanted, if the high bit of the next-to-last byte was not zero. This
        // is because BigIntegers are represented with twos-compliment notation, thus if the high bit of the last
        // byte happens to be 1 another 8 zero bits will be added to ensure the number parses as positive. Detect
        // that case here and chop it off.
        var stripSignByte = bytes.Length > 1 && bytes[0] == 0 && bytes[1] >= 0x80;
        // Count the leading zeros, if any.
        var leadingZeros = 0;
        for (var i = 0; input[i] == Alphabet[0]; i++)
        {
            leadingZeros++;
        }
        // Now cut/pad correctly. Java 6 has a convenience for this, but Android can't use it.
        var tmp = new byte[bytes.Length - (stripSignByte ? 1 : 0) + leadingZeros];
        Array.Copy(bytes, stripSignByte ? 1 : 0, tmp, leadingZeros, tmp.Length - leadingZeros);
        return tmp;
    }

    public by Geometry  1088  0  6  0

    FromData: Creates a set of decision variables from input data.

    Creates a set of decision variables from input data. The input data. An array of objects initialized with the values from the codebook.
    /// <summary>
    ///   Creates a set of decision variables from input data.
    /// </summary>
    /// 
    /// <param name="inputs">The input data.</param>
    /// 
    /// <returns>An array of <see cref="DecisionVariable"/> objects 
    /// initialized with the values from the codebook.</returns>
    /// 
    public static DecisionVariable[] FromData(double[][] inputs)
    {
        int cols = inputs.Columns();
        var variables = new DecisionVariable[cols];
        for (int i = 0; i < variables.Length; i++)
            variables[i] = new DecisionVariable(i.ToString(), DecisionVariableKind.Continuous);
        return variables;
    }

    public by Geometry  1031  0  6  0

    FromTree: Creates a new <see cref="KNearestNeighbors"/> algorithm from an existing <see cref="KDTree{T}"/>. The tree must have been created using the input points and the point's class labels as the associated node information.

    Creates a new algorithm from an existing . The tree must have been created using the input points and the point's class labels as the associated node information. The containing the input points and their integer labels. The number of nearest neighbors to be used in the decision. The number of classes in the classification problem.
    /// <summary>
    ///   Creates a new <see cref="KNearestNeighbors"/> algorithm from an existing
    ///   <see cref="KDTree{T}"/>. The tree must have been created using the input
    ///   points and the point's class labels as the associated node information.
    /// </summary>
    /// 
    /// <param name="tree">The <see cref="KDTree{T}"/> containing the input points and their integer labels.</param>
    /// <param name="k">The number of nearest neighbors to be used in the decision.</param>
    /// <param name="classes">The number of classes in the classification problem.</param>
    /// <param name="inputs">The input data points.</param>
    /// <param name="outputs">The associated labels for the input points.</param>
    /// 
    /// <returns>A <see cref="KNearestNeighbors"/> algorithm initialized from the tree.</returns>
    /// 
    public static KNearestNeighbors FromTree(KDTree<int> tree, int k, int classes, double[][] inputs, int[] outputs)
    {
        var knn = new KNearestNeighbors(tree, k, classes, inputs, outputs, tree.Distance);
    
        return knn;
    }
    • Public Snippets
    • Channels Snippets