0

It turns out building the following string in python...

# global variables
cr = '\x0d' # segment terminator
lf = '\x0a' # data element separator
rs = '\x1e' # record separator
sp = '\x20' # white space

a = 'hello'
b = 'world'

output = a + rs + b

...is not the same as it may be in C#.

How do I accomplish the same in C#?

3
  • Can show the literal result you are looking for. Commented Mar 27, 2013 at 16:25
  • Strings in C# are enclosed in quotes, ". Commented Mar 27, 2013 at 16:25
  • I get the double quotes part. What I mean is, C# gives errors with you try to build a string of hex characters and normal strings. Commented Mar 27, 2013 at 16:26

2 Answers 2

1

Without knowing what you're trying to accomplish you can encapsulate that in a class.

public class StringStuff
{
    private const char cr = '\x0d'; // segment terminator
    private const char lf = '\x0a'; // data element separator
    private const char rs = '\x1e'; // record separator
    private const char sp = '\x20'; // white space

    public string BuildString()
    {
        var a = "hello";
        var b = "world";

        var output = a + rs + b

        return output;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

not sure what you are trying to accomplish but try this:

// global variables
char cr = '\x0d'; // segment terminator
char lf = '\x0a'; // data element separator
char rs = '\x1e'; // record separator
char sp = '\x20'; // white space

string a = "hello";
string b = "world";

string output = a + rs + b;

You can also use string instead of char but then use double quotes instead of single quotes.

1 Comment

Good lord. I think I was awake for too long last night converting python code to C# and started writing code outside of functions... Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.