Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Finding something after a search term

Name: Anonymous 2018-09-30 1:43

How can you determine if there are more bytes to a file after a certain string? I want to parse a file, find a certain combination of values, and then see if that's the end of the file or not. What will happen next depends on whether that's the end or not. Any ideas?

Name: Anonymous 2018-09-30 10:08

You could check if you're at the end of the file.

Name: Anonymous 2018-09-30 13:40

/string(.+)/s
if $1 { do stuff }


Now you have two problems!

Name: Anonymous 2018-09-30 14:07

>>2
Not exactly the same. I am trying to check if there exists any data after a search term, which I am expecting to be in the file. There are two options: the search term might be at the end, or there might be something after it. If there is something after it, do something else. In this case, I made it so that it will save the contents of the stuff after the search term to a file.

I think I found something suitable:
String searchTerm = ""; //put what I want to find here, but I don't want to put it on /prog/
Scanner whatever = new Scanner(filename);
byte[3] tempBytes;
tempBytes[0] = whatever.nextByte();
tempBytes[1] = whatever.nextByte();
tempBytes[2] = whatever.nextByte();
boolean searchTermNotFound = true;
boolean stuffAfterSearchTerm = false;
do {
String tempByteString = tempBytes.toString();
if (tempByteString == searchTerm) {
searchTermNotFound = false;
if (whatever.hasNextByte()) {
stuffAfterSearchTerm = true;
}
} else if (whatever.hasNextByte()) {
tempBytes[0] = { whatever.nextByte() };
if (whatever.hasNextByte()) {
tempBytes[1] = { whatever.nextByte() };
} else {
System.out.println("not enough bytes to complete full string thing");
}
if (whatever.hasNextByte()) {
tempBytes[2] = { whatever.nextByte() };
} else {
System.out.println("not enough bytes to complete full string thing");
}
} else {
System.out.println("not enough bytes to complete full string thing");
}
} while (whatever.hasNextByte() && searchTermNotFound);

if (stuffAfterSearchTerm) {
System.out.println("this is where I would save the remaining contents to a file but I am lazy");
}


I guess this would work? I didn't even try it in an IDE yet, and there is probably a better way to do it. Is this even the right way to convert hex values to strings? Probably not. And I know my control structures are weird and inefficient. I'm tired so this is bad even for my standards.

Name: Anonymous 2018-09-30 14:59

pseudocode
f = open(filename)
position = 0
while f.read(search_term.length) as found:
if found == search_term:
if f.read(1) == EOF:
return "found at end of file"
else:
return "found before end of file"
f.seek(++position)
return "not found"

Name: Anonymous 2018-09-30 15:18

>>5
lol is this supposed to be python? thanks tho

Name: Anonymous 2018-09-30 17:53

>>6
do your own homework, illiterate-kun

Name: Anonymous 2018-09-30 19:15

>>7
no

Name: Anonymous 2018-09-30 19:19

>>7
I'm the OP, and believe it or not, I'm programming for a personal project, not a class assignment. Just because someone isn't an EXPERT PROGRAMMER doesn't mean everything they program is for homework.
>>8
You didn't make this thread, so why answer for me?

Name: Anonymous 2018-09-30 20:43

>>9
get out of my thread

Name: Anonymous 2018-09-30 21:59

How do you determine if a file contains dubs?

Name: Anonymous 2018-09-30 23:16

>>11
grep -E '([[:digit:]])\1\b' FILE 

Name: Anonymous 2018-10-01 7:22

Is some autistic entity trying to build a spambot to poast here using the collective intelligence of /proggles/? This is a second thread about text processing that displays a lack of basic understanding.

Name: Anonymous 2018-10-01 15:02

>>13
OP here. This isn't text processing, it's processing of binary data. I don't want to be too specific though. And no, it's not s spam not. I don't see how you could possibly misconstrue this as being for spam. But regardless, I'm not going to tell you what it's really for.

Name: Anonymous 2018-10-01 18:00

>>14
Admit your role or perish.

Name: Anonymous 2018-10-02 6:29

>>14
hey /prog/ please solve me the problem that I will only describe vaguely

regardless, the solution is the same: just check if your're are at EOF

Name: Anonymous 2018-10-02 10:42

check my dubs

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List