Jump to content

Reading text from a string in a special way

- - - - -

  • Please log in to reply
5 replies to this topic

#1
bojan_p87

bojan_p87

    Newbie

  • Members
  • Pip
  • 4 posts
Hello

How to read text from string like this
"11KI ST1 INCEL0.0000 "
From this I ned to rewrite string to look like this :\
" ST1 INCEL 0.0000"
"INCEL 0.0000"
wheare
"11KI ST1 INCEL0.0000 *empty spaces* " hawe constant leanght (for example "0.0000" begin on 37 place)

I dont know haw to separate "INCEL0.0000 TO "INCEL 0.0000"

Thanks for answer
Heare is example of the file and i get string from text line
[ATTACH]3691[/ATTACH]

Attached Files



#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Well my first instinct is to use string.Replace, basically you must read the text into a string right?(I didnt download your source, since your such a new member) Anyway once you have the text in a string you could do something like this:
string yourText = "11KI ST1 INCEL0.0000";
            yourText = yourText .Replace("11KI", "");
            yourText = yourText .Replace("INCEL", "INCEL ");
That should be pretty obvious, as to how it works, but if you dont understand: .Replace("ToReplace", "ReplaceWith");

Good luck ~ Committed. :)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
bojan_p87

bojan_p87

    Newbie

  • Members
  • Pip
  • 4 posts
Thank you for the quick response. But in my case "INCEL" could be anything, it was named the orientation and when I measur on field with instrument I can input any name for orientation. if you look to the entire file you vill see for the kod "11KI" orientation can have any name so I need an algorithm that will separate the data that is read from the file based on the length and write it into another file in specific places.

I need to get file (in attachment) for first "11KI" code;[ATTACH]3696[/ATTACH]

whware first 4 lines are not inportant and you can see that line no. 5 i get from my line in .sdr file wit "11KI" code
line 6,7 are my input text
line 8, 9 i get from "02TP" code (1.65 ~ 1.60)

line 10 is standard == 0.0
line 11,12,13,14,15 ... i get from code "09F1" and represent mesured points

wheare C is my input for specific point and i get that also based on the length of the string beginning


SImple for this string:

"CommittedC0der" i ned to get two strings
"Committed" and "C0der" based on string lenght :D

Attached Files



#4
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Well your above post was kind of hard to under stand, but hopefully this will work.

Btw, your .rar's have .sdr files in them, which I cant open.

Now assuming that each line you need to sort through is in the format of 2 numbers 2 letters, ST1 a 5 letter name and random number this code will work:
string yourText = "11KI ST1 INCEL0.0000";[COLOR=green]//This is what you would be reading in from the text file.[/COLOR]
 yourText = yourText.Substring(5, 15);[COLOR=green]//Substring the string, or basically take, the text starting from 5 chars in with a length of 15, making the new string "ST1 INCEL0.0000"[/COLOR]
            yourText = yourText.Insert(9, " ");[COLOR=green]//Now insert a " " 9 char's in making the string become "ST1 INCEL 0.0000"[/COLOR]
            MessageBox.Show(yourText);
Now this only works if the first orientation "11KI" or "02TP" stay 4 letters long, and that the second orientation "INCEL" stays 5 letters long.

Hope you understand. ~ Committed. :)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#5
bojan_p87

bojan_p87

    Newbie

  • Members
  • Pip
  • 4 posts
Sory for my bad english . I will try and post heare if it is ok :)

#6
bojan_p87

bojan_p87

    Newbie

  • Members
  • Pip
  • 4 posts

CommittedC0der said:

Well your above post was kind of hard to under stand, but hopefully this will work.

Btw, your .rar's have .sdr files in them, which I cant open.

Now assuming that each line you need to sort through is in the format of 2 numbers 2 letters, ST1 a 5 letter name and random number this code will work:
string yourText = "11KI ST1 INCEL0.0000";[COLOR=green]//This is what you would be reading in from the text file.[/COLOR]

 yourText = yourText.Substring(5, 15);[COLOR=green]//Substring the string, or basically take, the text starting from 5 chars in with a length of 15, making the new string "ST1 INCEL0.0000"[/COLOR]

            yourText = yourText.Insert(9, " ");[COLOR=green]//Now insert a " " 9 char's in making the string become "ST1 INCEL 0.0000"[/COLOR]

            MessageBox.Show(yourText);
Now this only works if the first orientation "11KI" or "02TP" stay 4 letters long, and that the second orientation "INCEL" stays 5 letters long.

Hope you understand. ~ Committed. :)

Greath thank you wery much :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users