Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String Find and Replace
#6
Aye, it's for anything that you might apply a set format for.

The String.Get.Part let's us specify a part of a string that we're searching for, which might change formatting depending on area or local.   

For example area lets go with "LLLLLLLLLLLLLLL, FFFFFFFFFFFFFFF".

Now on one format, that might be a string for Last name, First name (as designated by L and F.)
Instead of manually having to hard code into our program "Last name starts at position 1, is 15 characters.  First name is at position 17, is 15 characters.", or parse for commas and such, we just set a form pattern in that format and specify we want the part called "FFFFFFFFFFFFFFF" for the first name.

One form might have First name then last.  Another might have Last name then first.  A third form might have middle initial.   A fourth might have room for a title or suffix.  "DR Joe D Blowhard III, ESQ".    As long as we know the pattern, we can just grab out the part that we want from that form.

Dates were where this concept started, simply because it's something that we see which varies a lot.

MM/DD/YYYY  <-- US dates.
DD/MM/YYYY  <-- European dates.
YYYY/MM/DD  <-- Easily sorted computer dates.

Of course there's also various separators per region.  "MM/DD/YYYY" vs "MM-DD-YYYY" vs "MM.DD.YYYY" vs...  agggh!!!  The data we might want to gather might be shuffled around inside the damn localized formatting and be anywhere in the flipping world inside that string!!

So, this asks us to specify the localized format string that we should use and then asks for the part that we're looking for.

My format$ is "MM/DD/YYYY", I want the "MM" from this one.
Click.  format$ is now "DD/MM/YYYY".  I still want the "MM" from this one.
Click.  format$ is now "WWW, MM DD, YYYY".  I want the "MM".  (format such as "Fri, 03 14, 2025")

Give it the source$, the format$, and the part of that format$ and it fetches that part back for you.  That's what String.Get.Part does.  Smile

The String.Part.Replace works the same way.  You may not know where the MM is if the user changes local, but you want to update the info for one part in that form.   You simply send it the source string and valid format, tell it the part you're looking to replace, and then replace it with the proper data -- wherever it occurs in the string.

It's the flexibility to allow *the users* to set a custom format for a form so that it fits their localized standards, and for you to still be able to get and replace the information out of it.

Any place where data might be jumbled to a different format, all you need to know is the format style, specify it, and then you can grab or replace that part of the data.

"Steve.... 51 (555) 555-5555 123 Steve House Steveland, Stevestate 12345"

There's a lot of information in the line up above.  Name, age, phone number, street address city, state zipcode.  Any of that could appear in various forms, or not.  Some forms might have extra information like Last Name included.  Others might have some of that info removed for privacy reasons.    

None of that matter though as long as I can specify a format string for the data I'm looking for.  

I want ".........??......................................................................................." the data that corresponds to my ?? in this form.  That's my AGE.   In another form it might be in a different position.  Doesn't matter.  I just say I want "..........??" that part of that form.

Take any string.  Specify the format that it's in.  Choose the part you want.  Get or Replace that part if you like. 

^ That's what the functions above do for us.  Dates are just a good example and easy thing to use for them, but they allow for the flexibility to grab the data we want, no matter the format that it's in, and interact with it for us.  Wink
Reply


Messages In This Thread
String Find and Replace - by SMcNeill - 04-22-2025, 04:41 PM
RE: String Find and Replace - by SMcNeill - 04-24-2025, 07:19 AM
RE: String Find and Replace - by SMcNeill - 05-09-2025, 11:41 PM
RE: String Find and Replace - by bplus - 05-10-2025, 12:58 AM
RE: String Find and Replace - by bplus - 05-10-2025, 11:10 AM
RE: String Find and Replace - by SMcNeill - 05-10-2025, 12:02 PM



Users browsing this thread: 3 Guest(s)