Grasshopper

algorithmic modeling for Rhino

How to read a portion of a text file line from left using C#

Hi, 

I would like to reference a text file and read a small portion of all of the lines in the document to check whether it is equal to a string i am looking for. The string will always be in the first 4 characters of a line which is which I want to use a command similar to "left" in excel/VBA. 

All of the syntaxes I have found online do not work in GH. GH doesn't know what to do with the term "left" - (1. Error (CS0103): The name 'Left' does not exist in the current context (line 75)). Does anyone know a syntax for this that GH will accept?

Furthermore, can someone explain why these syntax mismatches happen? surely c# is the same no matter where you are using it?

Thanks a bunch!

ken 

Views: 1332

Replies to This Discussion

PROBLEM SOLVED:

Perfect!

string str = yourStringVariable.Substring(0,5); works great for my purpose. 


No chance you can explain why this command works in the gh component but others i have found online do not? Is there different types of C# or dlls that gh is referencing that something like Microsoft Visual Studio would be referencing differently?

Thanks so much!

Ken 

By "command" you mean string class Method(s)?

https://msdn.microsoft.com/en-us/library/system.string%28v=vs.110%2...

 ... others i have found online do not ...

List some "other" Methods.

  ... different types ...

you mean .NET versions? (supporting C# "builds": 4,5,...)

others:

http://snipplr.com/view/2500/

string line = "this is a string";

 console.writeline(left(line,5));    doesnt work. even as just left(line,5);

error: 1. Error (CS0103): The name 'Left' does not exist in the current context (line 75)

different types:

yes, i assume...I am unfamiliar with coding and terminology. Rhino uses .Net right? what is the alternative to .Net? does visual studio also use .Net? Why would anyone choose to use .Net over an alternative. If there is an article that explains this please just link it to me. 

Thanks for your help, I know its a big ask. 

Ken 

Strings et all: You forgot the class  that owns the Method:

string Massacre= LeftRightMid.Left(myString, 4);

see attached

A bit amusing (kinda) explanations upon what .NET is ... hmm... later (for the no funny aspect: Google it).

Attachments:

hahahaha well i guess that kind of explains the gist of it....il have to google it a bit too though. Thanks for all of your help!

Dr. StrangeLove (a strategic Microsoft partner [literally]) talks:

The Evil in a nutshell:

https://www.google.gr/url?sa=t&rct=j&q=&esrc=s&sour...

https://www.google.gr/url?sa=t&rct=j&q=&esrc=s&sour...

you can use... C# substring method

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service