Avatar billede lalledenby Nybegynder
28. maj 2002 - 15:21 Der er 14 kommentarer og
1 løsning

Del en tekststreng!?

jeg har en en .asp-fil som indsætter en tekststreng i en access database, men strengen er for stor... hvad skal jeg gøre? kan jeg dele den op med en asp kommando så den bliver sat ind i to felter? eller hvad?

-hjælp mig så hurtigt som muligt....
Avatar billede -master-d- Nybegynder
28. maj 2002 - 15:22 #1
Hvilket felt bruger du ?
Det må næsten være et tekstfelt
du skal bruge et notat felt.

Ellers må du splitte den op, men 65.000 tegn tror jeg næppe din streng er på.
Avatar billede terry Ekspert
28. maj 2002 - 15:22 #2
You can use Left and Mid functions
Avatar billede hathor Nybegynder
28. maj 2002 - 15:23 #3
200 point?? VILDT.

Eh, du er godt klar over at sådan en tekst-streng virkelig skal være motherfucking stor for ikke at kunne være i databasen ikke? Kan du ikke bare lave feltet til 32 bit?

/Hathor
28. maj 2002 - 15:23 #4
Jeg ved ikke om kommandoen er tilgængelig i ASP, men funktionerne Left, Right og Mid bruges jo til at dele tekster op med!
28. maj 2002 - 15:25 #5
Left("ABCD",2) = "AB"
Mid("ABCDEFG",3,3) = "CDE"
Right("ABCDEFG",4) = "DEFG"
Avatar billede lalledenby Nybegynder
28. maj 2002 - 15:27 #6
se min side her: http://80.196.119.125/blaabog...
databasen hedder.. http://80.196.119.125/blaabog/blaabog/.mdb
og aspfilen som ændsætter det er: http://80.196.119.125/blaabog/add_comments.asp
og den siden man taster informationerne ind i er: http://80.196.119.125/blaabog/default.asp
Avatar billede lalledenby Nybegynder
28. maj 2002 - 15:33 #7
det kan ske jeg har forklaret mig selv underligt...
<% Option Explicit %>
<!--#include file="common.inc" -->
<%
'Set the response buffer to true as we maybe redirecting
Response.Buffer = True

'Dimension variables
Dim rsSmut                 'Database Recordset holding the smut table
Dim rsAddNewComments            'Database recordset to add new comments
Dim strInputNavn
Dim strInputAdresse
Dim strInputPostnummer
Dim strInputBy
Dim strInputEmail
Dim strInputMobil
Dim strInputTlf
Dim strInputKaelenavn
Dim strInputRumbo
Dim strInputSavne
Dim strInputMotto
Dim strInputElevnr
Dim strInputBummert
Dim strInputSavne2
Dim strInputMotto2
Dim strInputKaelenavn2
Dim strInputBummert2
Dim strInputSavne3
Dim strInputMotto3
Dim strInputKaelenavn3
Dim strInputBummert3
Dim saryCommentWord             'Array to hold each word in the comments enetred by the user
Dim intCheckWordLengthLoopCounter    'Loop counter
Dim intWordLength            'Holds the length of the word to be checked
Dim blnWordLenthOK            'Boolean set to False if any words in the description are above 30 characters
Dim intLongestWordLength         'Holds the number of characters in the longest word entered in the description



strInputNavn = Request.Form("navn")
strInputAdresse = Request.Form("adresse")
strInputPostnummer = Request.Form("postnummer")
strInputBy = Request.Form("by")
strInputEmail = Request.Form("email")
strInputMobil = Request.Form("mobil")
strInputTlf = Request.Form("tlf")
strInputKaelenavn = Request.Form("kaelenavn")
strInputBummert = Request.Form("bummert")
strInputElevnr = Request.Form("elevnr")
strInputRumbo = Request.Form("rumbo")
strInputSavne = Request.Form("savne")
strInputMotto = Request.Form("motto")
strInputKaelenavn2 = Request.Form("kaelenavn2")
strInputBummert2 = Request.Form("bummert2")
strInputSavne2 = Request.Form("savne2")
strInputMotto2 = Request.Form("motto2")
strInputKaelenavn3 = Request.Form("kaelenavn3")
strInputBummert3 = Request.Form("bummert3")
strInputSavne3 = Request.Form("savne3")
strInputMotto3 = Request.Form("motto3")

'Split-up each word in the comments from the user to check that no word entered is over 50 characters
saryCommentWord = Split(Trim(strInputBummert), " ")
   
'Initialse the word length variable
blnWordLenthOK = True
   
'Loop round to check that each word in the comments entered by the user is not above 50 characters
For intCheckWordLengthLoopCounter = 0 To UBound(saryCommentWord)
   
    'Initialise the intWordLength variable with the length of the word to be searched
    intWordLength = Len(saryCommentWord(intCheckWordLengthLoopCounter))
   
    'Get the number of characters in the longest word
    If intWordLength => intLongestWordLength Then
        intLongestWordLength = intWordLength
    End If
       
    'If the word length to be searched is more than or equal to 50 then set the blnWordLegthOK to false
    If intWordLength => 50 Then
        blnWordLenthOK = False
               
    End If
Next



'Change my own codes for bold and italic HTML tags back to the normal satndrd HTML tags now that the check for unwated HTML tags is over
strInputBummert = Replace(strInputBummert, "[B]", "<b>", 1, -1, 1)
strInputBummert = Replace(strInputBummert, "[/B]", "</b>", 1, -1, 1)
strInputBummert = Replace(strInputBummert, "[I]", "<i>", 1, -1, 1)
strInputBummert = Replace(strInputBummert, "[/I]", "</i>", 1, -1, 1)
strInputBummert = Replace(strInputBummert, "[U]", "<u>", 1, -1, 1)
strInputBummert = Replace(strInputBummert, "[/U]", "</u>", 1, -1, 1)



'Change the emotion symbols for the path to the relative smiley icon
strInputBummert = Replace(strInputBummert, ":)", "<img src=""guestbook_images/smiley1.gif"" width=""17"" height=""17"">")
strInputBummert = Replace(strInputBummert, ";)", "<img src=""guestbook_images/smiley2.gif"" width=""17"" height=""17"">")
strInputBummert = Replace(strInputBummert, ":o", "<img src=""guestbook_images/smiley3.gif"" width=""17"" height=""17"">")
strInputBummert = Replace(strInputBummert, ":D", "<img src=""guestbook_images/smiley4.gif"" width=""17"" height=""17"">")
strInputBummert = Replace(strInputBummert, ":errr:", "<img src=""guestbook_images/smiley5.gif"" width=""17"" height=""17"">")
strInputBummert = Replace(strInputBummert, ":(", "<img src=""guestbook_images/smiley6.gif"" width=""17"" height=""17"">")
strInputBummert = Replace(strInputBummert, "X(", "<img src=""guestbook_images/smiley7.gif"" width=""17"" height=""17"">")


'Replace the vb new line code for the HTML new break code
strInputBummert = Replace(strInputBummert, vbCrLf, "<br>")


'Get rid of repeated return key hits so there arn't two many new lines going half way down the page (<br> is the HTML tag for new line)
'Loop though the comments entered by the user till all cases of two new lines togather are replaced by one new line
Do While InStr(1, strInputBummert, "<br><br>" ,vbTextCompare) > 0
   
    'Replace <br><br> with one case of <br>
    strInputBummert = Replace(strInputBummert , "<br><br>", "<br>")
Loop

'Create recorset object
Set rsSmut = Server.CreateObject("ADODB.Recordset")

'Replace swear words with other words with ***   
'Initalise the SQL string with a query to read in all the words from the smut table
strSQL = "SELECT tblSmut.* FROM tblSmut;"

'Open the recordset
rsSmut.Open strSQL, strCon

'Loop through all the words to check for


'Reset recordset
Set rsSmut = Nothing


'Write to the database if there are no unwanted HTML tags or the word lengths in the commets entered by the user are OK
If blnWordLenthOK = True Then
   
    'Create recorset object
    Set rsAddNewComments = Server.CreateObject("ADODB.Recordset")
   

    'Initalise the SQL string with a query to read in all the comments from the database
    strSQL = "SELECT kommentarer.* FROM kommentarer;"
   
    'Set the cursor type property of the record set to Dynamic so we can navigate through the record set
    rsAddNewComments.CursorType = 2
   
    'Set the Lock Type for the records so that the record set is only locked when it is updated
    rsAddNewComments.LockType = 3
   
    'Open the recordset
    rsAddNewComments.Open strSQL, strCon
   
    'Add a new record to the recordset
    rsAddNewComments.AddNew
   
    rsAddNewComments.Fields("rumbo") =  strInputRumbo
    rsAddNewComments.Fields("elevnr") =  strInputElevnr
    rsAddNewComments.Fields("navn") =  strInputNavn
    rsAddNewComments.Fields("adresse") =  strInputAdresse
    rsAddNewComments.Fields("postnummer") =  strInputPostnummer
    rsAddNewComments.Fields("by") =  strInputBy
    rsAddNewComments.Fields("email") =  strInputEmail
    rsAddNewComments.Fields("mobil") =  strInputMobil
    rsAddNewComments.Fields("tlf") =  strInputTlf
    rsAddNewComments.Fields("kaelenavn") =  strInputKaelenavn
    rsAddNewComments.Fields("bummert") =  strInputBummert
    rsAddNewComments.Fields("savne") =  strInputSavne
    rsAddNewComments.Fields("motto") =  strInputMotto
    rsAddNewComments.Fields("kaelenavn2") =  strInputKaelenavn
    rsAddNewComments.Fields("bummert2") =  strInputBummert
    rsAddNewComments.Fields("savne2") =  strInputSavne
    rsAddNewComments.Fields("motto2") =  strInputMotto
    rsAddNewComments.Fields("kaelenavn3") =  strInputKaelenavn
    rsAddNewComments.Fields("bummert3") =  strInputBummert
    rsAddNewComments.Fields("savne3") =  strInputSavne
    rsAddNewComments.Fields("motto3") =  strInputMotto
               
    'Update the database with the new recordset
    rsAddNewComments.Update
   
    'Requery the database to make sure that the new comments have been added
    'This will make the script wait until Database has updated itself as sometimes Access can be a little slow at updating
    rsAddNewComments.Requery
       
       
    'Reset Sever Objects
    Set adoCon = Nothing
    Set rsAddNewComments = Nothing

    'Return to the guestbook
    Response.Redirect "tak.asp?PagePosition=1"

End If
%>

<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Sign the Guest Book - Error</TITLE>


   
<!-- Display an error message -->
<script  language="JavaScript">
<!-- Hide from older browsers...

    //Display an error message in an alert box
    window.alert('Sorry one of the words used in your comments has <% = intLongestWordLength %> characters\nPlease shortern the length of this word to below 50 characters');
   
    //Return the user to there comments
    self.location.href='java script:history.back(1)';
// -->
</script> 
</head>
<body bgcolor="<% = strBgColour %>" text="<% = strTextColour %>" link="<% = strLinkColour %>" vlink="<% = strVisitedLinkColour %>" alink="<% = strActiveLinkColour %>">

</body>
</html>
Avatar billede -master-d- Nybegynder
28. maj 2002 - 15:56 #8
Ja men sagde du ikke at du bare havde et problem med en streng der var for lang til dit felt ?
Avatar billede lalledenby Nybegynder
28. maj 2002 - 16:00 #9
jo, det er mit problem...
jeg har lavet databasen i access og der står at jeg max kan bruge 255 tegn...
er der ingenting jeg kan gøre?
Avatar billede -master-d- Nybegynder
28. maj 2002 - 16:07 #10
Det har jeg sådan set skrevet til start

Gå ind i designvisning -> under datatype bruger du tekst, du skal bruge notat.

og så er den der der kan være og 65000 tegn.
28. maj 2002 - 16:19 #11
Der kan rent faktisk være op til 2 GByte hvis blot data ikke indtastes direkte i tabellen/formularen
Avatar billede -master-d- Nybegynder
28. maj 2002 - 20:10 #12
Du sagde selv det skulle gå så hrutigt som muligt, så virker det eller skal du have mere hjælp.
Avatar billede terry Ekspert
29. maj 2002 - 08:11 #13
use a memo field as master-d has stated!
Avatar billede hathor Nybegynder
02. juni 2002 - 14:14 #14
Hallo lever du?
Avatar billede lalledenby Nybegynder
03. juni 2002 - 10:18 #15
Jeg takker, det skulle gå hurtigt... he he, glemte lige dit svar... ups!
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester