GetCharsFromString() public static method

Copies an array of chars obtained from a String into a specified array of chars
public static GetCharsFromString ( string sourceString, int sourceStart, int sourceEnd, char &destinationArray, int destinationStart ) : void
sourceString string The String to get the chars from
sourceStart int Position of the String to start getting the chars
sourceEnd int Position of the String to end getting the chars
destinationArray char Array to return the chars
destinationStart int Position of the destination array of chars to start storing the chars
return void
示例#1
0
        public static sbyte[] decode(string encodedString)
        {
            var c = new char[encodedString.Length];

            SupportClass.GetCharsFromString(encodedString, 0, encodedString.Length, ref c, 0);
            return(decode(c));
        }
示例#2
0
        public CharPointer(string str)
        {
            int len = str.Length;

            _array = new char[len + 1];
            SupportClass.GetCharsFromString(str, 0, len, ref _array, 0);
            _array[len] = '\x0000';
            _index      = 0;
        }
示例#3
0
 /// <summary> Returns the path to the base package for model elements of the given version
 /// - e.g. "NHapi.Model.VXXX".
 /// This package should have the packages datatype, segment, group, and message
 /// under it. The path ends in with a slash.
 /// </summary>
 public static System.String GetVersionPackagePath(System.String ver)
 {
     System.Text.StringBuilder path = new System.Text.StringBuilder("NHapi.Model.V");
     char[] versionChars            = new char[ver.Length];
     SupportClass.GetCharsFromString(ver, 0, ver.Length, versionChars, 0);
     for (int i = 0; i < versionChars.Length; i++)
     {
         if (versionChars[i] != '.')
         {
             path.Append(versionChars[i]);
         }
     }
     path.Append("/");
     return(path.ToString());
 }
示例#4
0
 /// <summary> Returns the path to the base package for model elements of the given version
 /// - e.g. "ca/uhn/hl7v2/model/v24/".
 /// This package should have the packages datatype, segment, group, and message
 /// under it. The path ends in with a slash.
 /// </summary>
 public static System.String getVersionPackagePath(System.String ver)
 {
     if (Parser.validVersion(ver) == false)
     {
         throw new NuGenHL7Exception("The HL7 version " + ver + " is not recognized", NuGenHL7Exception.UNSUPPORTED_VERSION_ID);
     }
     System.Text.StringBuilder path = new System.Text.StringBuilder("Genetibase/NuGenHL7/model/v");
     char[] versionChars            = new char[ver.Length];
     SupportClass.GetCharsFromString(ver, 0, ver.Length, versionChars, 0);
     for (int i = 0; i < versionChars.Length; i++)
     {
         if (versionChars[i] != '.')
         {
             path.Append(versionChars[i]);
         }
     }
     path.Append('/');
     return(path.ToString());
 }
示例#5
0
        internal static string[] split(string in_Renamed, char splitchar)
        {
            ArrayList words;

            string[] ret;
            int      i;
            int      len;

            char[] str;
            int    wordstart = 0;

            // Create an array that is as big as the input
            // str plus one for an extra split char.

            len = in_Renamed.Length;
            str = new char[len + 1];
            SupportClass.GetCharsFromString(in_Renamed, 0, len, ref str, 0);
            str[len++] = splitchar;
            words      = new ArrayList(5);

            for (i = 0; i < len; i++)
            {
                // Compare this char to the split char
                // if they are the same the we need to
                // add the last word to the array.

                if (str[i] == splitchar)
                {
                    if (wordstart <= (i - 1))
                    {
                        words.Add(new string(str, wordstart, i - wordstart));
                    }
                    wordstart = (i + 1);
                }
            }

            // Create an array that is as big as the number
            // of elements in the vector, copy over and return.

            ret = new string[words.Count];
            words.CopyTo(ret);
            return(ret);
        }
示例#6
0
        /**
         * Expands a UPC-E value back into its full, equivalent UPC-A code value.
         *
         * @param upce UPC-E code as string of digits
         * @return equivalent UPC-A code as string of digits
         */
        public static string convertUPCEtoUPCA(string upce)
        {
            char[] upceChars = new char[6];
            SupportClass.GetCharsFromString(upce, 1, 7, upceChars, 0);
            StringBuilder result = new StringBuilder(12);

            result.Append(upce[0]);
            char lastChar = upceChars[5];

            switch (lastChar)
            {
            case '0':
            case '1':
            case '2':
                result.Append(upceChars, 0, 2);
                result.Append(lastChar);
                result.Append("0000");
                result.Append(upceChars, 2, 3);
                break;

            case '3':
                result.Append(upceChars, 0, 3);
                result.Append("00000");
                result.Append(upceChars, 3, 2);
                break;

            case '4':
                result.Append(upceChars, 0, 4);
                result.Append("00000");
                result.Append(upceChars[4]);
                break;

            default:
                result.Append(upceChars, 0, 5);
                result.Append("0000");
                result.Append(lastChar);
                break;
            }
            result.Append(upce[7]);
            return(result.ToString());
        }
示例#7
0
        /// <summary>
        /// Creates new EncodingCharacters object with the given character
        ///
        /// values. If the encodingCharacters argument is null, the default
        ///
        /// values are used.
        ///
        /// </summary>
        /// <param name="encodingCharacters">consists of the characters that appear in
        ///
        /// MSH-2 (see section 2.8 of the HL7 spec).  The characters are
        ///
        /// Component Separator, Repetition Separator, Escape Character, and
        ///
        /// Subcomponent Separator (in that order).
        ///
        /// </param>

        public EncodingCharacters(char fieldSeparator, System.String encodingCharacters)
        {
            this.fieldSep = fieldSeparator;

            this.encChars = new char[4];

            if (encodingCharacters == null)
            {
                this.encChars[0] = '^';

                this.encChars[1] = '~';

                this.encChars[2] = '\\';

                this.encChars[3] = '&';
            }
            else
            {
                SupportClass.GetCharsFromString(encodingCharacters, 0, 4, this.encChars, 0);
            }
        }
示例#8
0
        /// <summary>
        /// Creates new EncodingCharacters object with the given character
        /// values. If the encodingCharacters argument is null, the default
        /// values are used.
        /// </summary>
        /// <param name="fieldSeparator">The field separator.</param>
        /// <param name="encodingCharacters">
        /// Consists of the characters that appear in
        /// MSH-2 (see section 2.8 of the HL7 spec). The characters are
        /// Component Separator, Repetition Separator, Escape Character, and
        /// Subcomponent Separator (in that order).
        /// </param>
        public EncodingCharacters(char fieldSeparator, string encodingCharacters)
        {
            FieldSeparator = fieldSeparator;

            encChars = new char[4];

            if (encodingCharacters == null)
            {
                encChars[0] = '^';

                encChars[1] = '~';

                encChars[2] = '\\';

                encChars[3] = '&';
            }
            else
            {
                SupportClass.GetCharsFromString(encodingCharacters, 0, 4, encChars, 0);
            }
        }
示例#9
0
        /// <summary>
        /// Creates new EncodingCharacters object with the given character
        /// values. If the encodingCharacters argument is null, the default
        /// values are used.
        /// </summary>
        /// <param name="fieldSeparator">The field separator.</param>
        /// <param name="encodingCharacters">
        /// Consists of the characters that appear in
        /// MSH-2 (see section 2.8 of the HL7 spec). The characters are
        /// Component Separator, Repetition Separator, Escape Character, and
        /// Subcomponent Separator (in that order).
        /// </param>
        /// <exception cref="HL7Exception">If encoding characters are not unique.</exception>
        public EncodingCharacters(char fieldSeparator, string encodingCharacters)
        {
            if (char.IsWhiteSpace(fieldSeparator) || fieldSeparator == char.MinValue)
            {
                throw new HL7Exception("Field Seperator must be a printable character.");
            }

            FieldSeparator = fieldSeparator;

            encChars = new char[4];
#if NET35
            if (string.IsNullOrEmpty(encodingCharacters) || encodingCharacters.Trim().Length == 0)
#else
            if (string.IsNullOrWhiteSpace(encodingCharacters))
#endif
            {
                encChars[0] = '^';

                encChars[1] = '~';

                encChars[2] = '\\';

                encChars[3] = '&';
            }
            else
            {
                if (encodingCharacters.Any(@char => char.IsWhiteSpace(@char) || @char == char.MinValue))
                {
                    throw new HL7Exception("Encoding characters must be printable characters.");
                }

                if (!SupportClass.CharsAreUnique(encodingCharacters))
                {
                    throw new HL7Exception("Encoding characters must be unique.");
                }

                SupportClass.GetCharsFromString(encodingCharacters, 0, 4, encChars, 0);
            }
        }
示例#10
0
        /// <summary> <P>Converts a float value into a string with the specified number of
        /// digits after the decimal place.</P>
        /// <P>Note: this function does not properly handle special case float
        /// values such as Infinity and NaN.</P>
        ///
        /// </summary>
        /// <param name="flote">the float value to convert to a string
        /// </param>
        /// <param name="nFrac">the number of digits to display after the decimal point
        ///
        /// </param>
        /// <returns> String representation of the float value with the specified
        /// number of digits after the decimal place.
        /// </returns>
        public static System.String toString(float flote, int nFrac)
        {
            // check for special case
            if (flote == f_POSITIVE_INFINITY)
            {
                return("Infinity");
            }
            else if (flote == f_NEGATIVE_INFINITY)
            {
                return("-Infinity");
            }
            //else if (flote != flote) // this is probably not necessary
            //return "NaN";

            // check for fast out (no fractional digits)
            if (nFrac <= 0)
            // round the whole portion
            {
                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                return(System.Convert.ToString((long)(flote + 0.5f)));
            }

            // extract the non-fractional portion
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            long fWhole = (long)flote;

            // figure out if it's positive or negative.  We need to remove
            // the sign from the fractional part
            float sign = (fWhole < 0)?-1f:1f;

            // figure out how many places to shift fractional portion
            float shifter = 1;

            for (int i = 0; i < nFrac; i++)
            {
                shifter *= 10;
            }

            // extract, shift, and round the fractional portion
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            long fFrac = (long)((flote - fWhole) * sign * shifter + 0.5f);

            // convert the fractional portion to a string
            System.String fracString = System.Convert.ToString(fFrac);
            int           fracLength = fracString.Length;

            // ensure that rounding the fraction didn't carry into the whole portion
            if (fracLength > nFrac)
            {
                fWhole    += 1;
                fracLength = 0;
            }

            // convert the whole portion to a string
            System.String wholeString = System.Convert.ToString(fWhole);
            int           wholeLength = wholeString.Length;

            // create the string buffer
            char[] floteChars = new char[wholeLength + 1 + nFrac];

            // append the non-fractional portion
            SupportClass.GetCharsFromString(wholeString, 0, wholeLength, floteChars, 0);

            // and the decimal place
            floteChars[wholeLength] = '.';

            // append any necessary leading zeroes
            int i2  = wholeLength + 1;
            int max = i2 + nFrac - fracLength;

            for (; i2 < max; i2++)
            {
                floteChars[i2] = '0';
            }

            // append the fractional portion
            if (fracLength > 0)
            {
                SupportClass.GetCharsFromString(fracString, 0, fracLength, floteChars, max);
            }

            return(new System.String(floteChars, 0, floteChars.Length));
        }