Long to Hex VB6, recode in c# [closed] - c#

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I want to code this part of a VB6 application in c#.
How can I change a long into a Hex value?
Public Function longToHex(l As Long) As String
longToHex = Hex(l)
If Len(longToHex) < 4 Then longToHex = String(4 - Len(longToHex), "0") & longToHex
longToHex = Right(longToHex, 2) & Left(longToHex, 2)
End Function

Just format to a padded hex string:
string.Format("{0:X4}", myLong.ToString().Length / 2)
Then transpose the first two characters with the last two.
The VB6 code appears to take the length of sData divided by 2, then converts the length to a Hex string and pads it with 0s to 4 characters if needed. It then transposes the first two characters with the last two.

Seems convoluted -- what is the code supposed to do? Half the length of the string in hex?
This might work: sLen = (sData.length / 2).ToString("X")

Related

Add comma before last character of a string in c# [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I need to put a comma before the last char of a string.
For example:
Input: 101919 = Ouput: 10191,9
What is the best way to do that?
if (input.Length > 0) { input = input.Insert(input.Length - 1, ","); }
With the insert method
strTarget = strTarget.Insert( srtrTarget.Length -1, ",");

How to save all words above 7 letters to a file [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I am currently working on a console text analysis program for an assignment.
My problem is, I need to save all user entered words above 7 letters to a text file. The user can enter words by typing in their paragraph or by loading from a text file.
Any ideas on how I can do this ?
Thanks for any help in advance
Without giving you the code, think about what you really need to do.
Read in the entire text.
Split the text based on spaces / punctuation to identify each word. This will be stored in an array.
Test each split string's length.
Write the results to a file.
I'm not sure how you're getting the user-entered words, but you can do a simple LINQ statement to get the words greater than 7 letters:
//get all words into an array (wordArray)
var bigWords = wordArray.Where(w => w.Length > 7).ToArray();
Then you do something with the bigWords array.
I'm not going to do your assignment for you.
You should check functions such as String.Split, String.Length and String.Substring()

Looking for SpanIncluding equivalent in C# [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I'm porting a c++ class to C# and i have a difficulty.
I would like to find an equivalent of SpanIncluding.
Here is my cpp code :
while (Notes.Mid(j,1).SpanIncluding("0123456789").IsEmpty()!=NULL){}
Anyone can help me please ?
I believe SpanIncluding starts matching from the start of the string, stopping when the first non-matching character is found.
So one formulation in the general case would be this:
string match = new string(someString.ToCharArray().
TakeWhile(c => "0123456789".Contains(c)).ToArray());
(or an equivalent using a regular expression).
However, in the example given in the question there's only one character so the whole thing probably boils down to a test of whether this character is >= '0' and <= '9':
while(char.IsDigit(Notes[j])) { ... };
I found the MSDN page for SpanIncluding, and it seems like a ridiculously specific function. I can't really understand what it tries to solve, since it has some strange caveats.
LINQ would be one way of implementing it:
string text = "2334562";
IEnumerable<char> spannedChars = text.TakeWhile(c => "1234567890".Contains(c));
This is a more direct port of SpanIncluding than queen3's option, if I understand the MSDN page correctly, because the result set should stop the minute it hits a character not in the spanning string.

Convert a get a character's unicode(?) value? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I need to convert a char to an int and back.
Here's what I'm using to convert the char to an int:
(char)65 // Returns 'a'
Here's what I'm TRYING to use to convert it back:
(int)'a' // Returns 97
Any ideas what I can do?
try this,
char x = 'a';
int y = (int)x;
65 is the character code for a capital 'A'. 97 is a lower case 'a'.

How to set limit in a regular expression? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I have got a regular expression which I want to be able to accept characters upto a minimum length of 11 characters as against 16 which is the case at the moment.
^[A-Za-z]{6}[0-9LMNPQRSTUV]{2}[A-Za-z]{1}[0-9LMNPQRSTUV]{2}[A-Za-z]{1}[0-9LMNPQRSTUV]{3}[A-Za-z]{1}$
Can some one please suggest the changes?
Thanks
Each {6} gives you the number of character you're expecting, here 6 for your 1st expression.
If you want a range of number of characters, do something like this : {1,6} and it will accept 1 to 6 characters at the beginning of your regex.
Which will give you from 11 to 16 characters in your Regex.
{n} - preceeding symbol (template) is expected to appear exactly n times
{min,max} - preceeding symbol (template) is expected to appear exactly minimum min times but not more than max times
Hope this helps you)

Categories

Resources