Hack Forums
[.NET] Splitting strings - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Splitting strings (/showthread.php?tid=4837463)



Splitting strings - halearn - May 26, 2015

this is a very basic tutorial i made because i have seen many people failing at this simple task ...
lets say you got this string "this is / a string" but you only want "this is" , here is what you do
Code
dim _str as string = "this is / a string"
dim temp = _srt.split("/") ' it will split the string by this character "/"
dim result as string = _srt(0) '0 is the first part , 1 is the second part and so on

another example of splitting by a word this time
the string this time is "abcd[www]efgh" , you need both the abcd part and the efgh on a separate strings
Code
dim _str as string = "abcd[www]efgh"
dim temp = _str.split("[www]")
dim first as string = temp(0)
dim second as string = temp(1)

thanks for viewing , hope that i have helped you.


* - CodeAssassin - May 26, 2015

(May 26, 2015 10:59 AM)halearn Wrote:  this is a very basic tutorial i made because i have seen many people failing at this simple task ...
lets say you got this string "this is / a string" but you only want "this is" , here is what you do
Code
dim _str as string = "this is / a string"
dim temp = _srt.split("/") ' it will split the string by this character "/"
dim result as string = _srt(0) '0 is the first part , 1 is the second part and so on

thanks for viewing , hope that i have helped you.

might want to edit it into a working tut at least :)

Your refrenced var is temp not _srt(0)


* - GhostCode - May 26, 2015

I wouldn't call this a tutorial to be honest
That's pretty much what is on msdn.
Why not expanding the tutorial a bit and explaining how Regex.Split() works and also talk about joining strings back together etc ;) ?


* - Ninja - May 26, 2015

Lol the tutorial won't even work.
You did "_srt(0)" while it should be "temp(0)". And temp should be a "String()", not a "String".


* - He B TeMy - May 27, 2015

(May 26, 2015 11:16 AM)Tyranitar Wrote:  Lol the tutorial won't even work.
You did "_srt(0)" while it should be "temp(0)". And temp should be a "String()", not a "String".

He's a fucking idiot but 'temp' is a String() there.

Anyway, i guess we may have a moderator next year to cleanup this shit.


* - CodeAssassin - May 27, 2015

(May 27, 2015 08:43 AM)He B TeMy Wrote:  He's a fucking idiot but 'temp' is a String() there.

Anyway, i guess we may have a moderator next year to cleanup this shit.

What happened to the last mod?

Thought it was SomeWhiteguy?


* - He B TeMy - May 27, 2015

(May 27, 2015 09:37 AM)sweetysuckscock Wrote:  What happened to the last mod?

Thought it was SomeWhiteguy?

The last one AFAIK was TUP, but he 'quit' shortly after.


* - Hiiro - May 27, 2015

(May 27, 2015 10:36 AM)He B TeMy Wrote:  The last one AFAIK was TUP, but he 'quit' shortly after.
This, I think he resigned due to exams or something.


* - CodeAssassin - May 27, 2015

(May 27, 2015 10:36 AM)He B TeMy Wrote:  The last one AFAIK was TUP, but he 'quit' shortly after.

Guess he got pissed with all the shit that goes with the job lol.

shame tho :( we do need a mod


* - Hiiro - May 27, 2015

(May 27, 2015 10:55 AM)sweetysuckscock Wrote:  Guess he got pissed with all the shit that goes with the job lol.

shame tho :( we do need a mod
No, he seems pretty tolerant; he was just extremely busy so his mod status just came at a bad time.


* - CodeAssassin - May 27, 2015

(May 27, 2015 11:02 AM)Loopy Weeaboo Wrote:  No, he seems pretty tolerant; he was just extremely busy so his mod status just came at a bad time.

Yeah i'm surprised he took it, as i know he is a very good coder and properly has a million and one projects on the go all the time.

Learnt from quite a few of his sources tbh. Nice guy always shared his knowledge.


* - irasch007 - May 27, 2015

(May 26, 2015 11:02 AM)sweetysuckscock Wrote:  might want to edit it into a working tut at least :)

Your refrenced var is temp not _srt(0)

Hmmmmm...

Dim MySplitString as stringt = "1|2|3"

textbox1.text = MySplitString.tostring.split("|")(0)
textbox2.text = MySplitString.tostring.split("|")(1)
textbox3.text = MySplitString.tostring.split("|")(2)


* - CodeAssassin - May 27, 2015

(May 27, 2015 11:20 AM)irasch007 Wrote:  Hmmmmm...

Dim MySplitString as stringt = "1|2|3"

textbox1.text = MySplitString.tostring.split("|")(0)
textbox2.text = MySplitString.tostring.split("|")(1)
textbox3.text = MySplitString.tostring.split("|")(2)

now do that on more 100+ lines...

have fun typing.... :)

Also "MySplitString" is sting no need to ".ToString()" a string.

actually what you on about?

check the quote in my post for the original code he used if not changed yet.


* - ShittyAdvice - May 27, 2015

(May 27, 2015 11:20 AM)irasch007 Wrote:  Hmmmmm...

Dim MySplitString as stringt = "1|2|3"

textbox1.text = MySplitString.tostring.split("|")(0)
textbox2.text = MySplitString.tostring.split("|")(1)
textbox3.text = MySplitString.tostring.split("|")(2)

No offense but this genuinely hurts my eyes.
Imagine having to do this a lot of times.
You're splitting the string again each time, do it once and save it.
This way if you run an async task that edits the string you suddenly have different results.