Jump to content

Recommended Posts

Posted

I have city names and adresses like that:

London XV. Small Street 3.

Bukarest V. Big Street 4.

Kijev New Street 55.

Okland VIII. olden street 33.

Sydney Small street 44.

 

All city names are one word names, but some of them has a district  code.

Because of that I am not able to Split the city name from adress correctly.

If a city has district code it's a roman number and it ends with a dot.

 

I want trim that way:

London XV.               |Small Street 3.

Bukarest V.                |Big Street 4.

Kijev                           |New Street 55.

Okland VIII.               |olden street 33.

Sydney                       |Small street 44.

 

| sign not necessarry I only want to trim this text

Thy in advance.

Posted (edited)
;~ London XV. Small Street 3
;~ Bukarest V. Big Street 4
;~ Kijev New Street 55
;~ Okland VIII. olden street 33
;~ Sydney Small street 44

$text = 'Okland VIII. olden street 33'

$i = StringInStr($text,'.',1) ; first dot
If $i > 0 Then ; remove VIII.
    $j = StringInStr($text,' ',1,-1,$i-1) ; first space to the left from dot
    If $j > 0 Then $text = StringLeft($text,$j-1) & StringMid($text,$i+1)
EndIf
ConsoleWrite($text&@CRLF)

$k = StringInStr($text,' ',1) ; split by first space
If $i > 0 Then
    $city = StringLeft($text,$k-1)
    $street = StringMid($text,$k+1)
    ConsoleWrite('city: '&$city&@CRLF)
    ConsoleWrite('street: '&$street&@CRLF)
EndIf

 

Edited by Zedna
Posted
1 hour ago, Jos said:

I think this is never going to be an easy one as one other issue could be when the City name consists of multiple words like "New York". :) 

That's what I thought too :lol:. There are most likely cases that cannot be accurately mapped from the available data.

2 hours ago, DannyJ said:

I have city names and adresses like that:

What is the source of these data? Is it possible to have a separation of the elements already at the creation process?

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Posted
5 hours ago, DannyJ said:

All city names are one word names

Assuming that this assertion is always true, here is a possible way

#Include <Array.au3>

$txt = "London XV. Small Street 3." & @crlf & _ 
    "Bukarest V. Big Street 4." & @crlf & _ 
    "Kijev New Street 55." & @crlf & _ 
    "Okland VIII. olden street 33." & @crlf & _ 
    "Sydney Small street 44."

$r = StringRegExpReplace($txt, '(?m)^\w+(\h+[A-Z]+\.)?\K(\h+)', "|")
Local $a[0][2]
_ArrayAdd($a, $r)
_ArrayDisplay($a)

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...